I want the column names and values in row wise manner.
i want to bind the Column names and values in C# server side.
I tried some Query But it shows only Column names ,But i want the corresponding values.
This is my Query
alter procedure sp_Trial
@id varchar(max)
as
begin
DECLARE @collist VARCHAR(max)='',
@sql NVARCHAR(max)
SELECT @collist += '(''' + COLUMN_NAME + ''',' + COLUMN_NAME + '),'
FROM INFORMATION_SCHEMA.columns
WHERE TABLE_NAME = 'tbl_seat'
--AND COLUMN_NAME LIKE 'Field%'
AND TABLE_SCHEMA = 'dbo'
SELECT @collist = LEFT(@collist, Len(@collist) - 1)
SET @sql ='
SELECT SeatNo
FROM tbl_seat
CROSS apply (VALUES' + @collist
+ ') ca (seatno, data)
WHERE Routeid='+@id+' and data =0'
EXEC Sp_executesql
@sql
end
6 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nitin SontakkePosted Jan 17, 2017, 3:00 AM
Vasanth JackPosted Jan 17, 2017, 12:50 AM
Nitin SontakkePosted Jan 16, 2017, 10:01 AM
Vasanth JackPosted Jan 16, 2017, 8:21 AM
Nitin SontakkePosted Jan 16, 2017, 6:30 AM
Saillesh PawarPosted Jan 16, 2017, 5:18 AM