Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Please help me with my SQL problem, I ma new to SQL server.

Please find my below image which shows that my actual raw table data and I have written below query to to the required output.

SQL
CREATE PROCEDURE GetImmediateManager
   @OSType varchar(10)
 
AS
BEGIN

DECLARE @columns VARCHAR(8000)
declare @str varchar(100)

SELECT @columns = COALESCE(@columns + ',[' + cast(osversion as varchar) + ']',
'[' + cast(osversion as varchar)+ ']')
FROM dbo.Table_1 where Type = '@OSType'
GROUP BY osversion

DECLARE @query VARCHAR(8000)
SET @query = 'SELECT *
FROM (select * from dbo.Table_1 where Type = ''' + '@OSType'+''' ) as t
PIVOT
(
MAX(Type)
FOR [OSVersion]
IN (' + @columns + ')
) AS p'

EXECUTE(@query)
END

Could you please help me how do I get multiple values returned from stored procedure. Once I get the SP data ,after I need to bind to Data Grid View.

Your quick response will be helps a lot for my development team,
Posted
Updated 30-Jul-14 17:14pm
v2
Comments
Nirav Prabtani 31-Jul-14 1:13am    
What is an issue??

You can store the results of your query in a temporary table.
Then select results over that table and return to the caller.
 
Share this answer
 
Thanks a lot Abhinav for your quick response.
I have resolved my problem with the below mentioned query

SQL
DECLARE @columns VARCHAR(8000)
DECLARE @strIn VARCHAR(8000)
SELECT @columns = COALESCE(@columns + ',[' + cast(OS_version as varchar) + ']',
'[' + cast(OS_version as varchar)+ ']')
FROM dbo.sp_MACPOSInformation1 where OS_Name = 'IOS'
GROUP BY OS_version

DECLARE @query VARCHAR(8000)

select @query =  'SELECT *
FROM (select * from dbo.sp_MACPOSInformation1 where OS_Name = '''+'IOS'+''' ) as t
PIVOT
(
MAX(OS_Name)
FOR [OS_version]
IN (' + @columns + ')
) AS p'

execute(@query)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900