I am working on SQL Server stored procedure. I have a table 'User' having fields (Id, Name, Email,Address).
I have following query returning All Users
select * from [User]
It returns all users, but I just want to insert following dummy user to resulting record before returning it.
User => Id = 0, Name = "All"
This record will not be present with in the database but while returning result I want to insert this record as first record and then remaining users. I tried to find something like this but in vain.
To insert a row into a table, you need to specify three things: First, the table, which you want to insert a new row, in the INSERT INTO clause. Second, a comma-separated list of columns in the table surrounded by parentheses. Third, a comma-separated list of values surrounded by parentheses in the VALUES clause.
To add a row number column in front of each row, add a column with the ROW_NUMBER function, in this case named Row# . You must move the ORDER BY clause up to the OVER clause.
SELECT 0 AS Id, 'All' AS Name
UNION ALL
SELECT Id, Name FROM Users;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With