September 30, 2019 at 9:24 pm
Hi-- please advise on the below sceanrio
SELECT * --- Question ) How can I replace "*" which is after select with column names, example the query is only looking for "Request_Status" in the WHERE clause so is it required that I still need to select Person_ID and additional columns. ( this code is part of an SP so wanted to avoid pasting to much code here and only pasted the part of Temp table which had the all in select)
FROM
(
SELECT Row_Number() over(order by Person_LastName, Person_FirstName) ROWID,
Person_ID,
Person_FirstName,
Person_LastName,
Person_SSN,
Person_Email,
Employee_Status,
Request_Status, -- This is what looks like it is looking for.
Registration_ID,
Registration_Opened,
Registration_Closed
FROM #tbPersonRegistration
WHERE Request_Status = @Request_Status_ID -- which is one of the INT variable while creating the SP
)as result
WHERE ROWID between @StartRow and @EndRow
END
GO
September 30, 2019 at 11:30 pm
You don't have to select all the columns - you can select one, two, three or whatever columns as long as they are part of the result set you are selecting from.
Sue
October 1, 2019 at 6:30 am
Are you trying to build the dynamic T-SQL query to SELECT the dynamic columns and filter using WHERE clause using dynamic columns ? If yes, then you can use the dynamic parameterized SQL. You can refer the below URL for help.
https://www.mssqltips.com/sqlservertip/1160/execute-dynamic-sql-commands-in-sql-server/
October 1, 2019 at 12:29 pm
if you get Redgate sql prompt , there is an option to expand *
I believe if you look at apexsql website you might also find a free tool that also does it - you can then just delete the column names from your code that you don't want
MVDBA
November 26, 2019 at 11:58 am
Since it is a part of SP, there must be some logic and requirements of other columns in the remaining SP code.
Get the requirements clear and eliminate the columns which are not at all required anywhere.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply