Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to convert row to cloumn with rows dynamic ?

Author  Topic 

headshot
Starting Member

9 Posts

Posted - 2015-05-21 : 11:27:36
Hello guys, I want to convert row to columns with rows dynamic .I have two table , i'll join them and get data.See at


Ok , i try convert rows to columns with PIVOT . i want the result as
GROUP_MOD_ID	ADD	EDIT	DELETE
G02 1 0 1



CREATE PROC GET_FUNC @GID CHAR(5)
AS
BEGIN
SELECT FUNCTION_MOD_NAME
FROM
( SELECT TEMP.FUNCTION_MOD_NAME,TEMP.ALLOW
FROM (SELECT A.GROUP_MOD_ID, B.FUNCTION_MOD_NAME,A.ALLOW
FROM FUNCTION_GROUP A INNER JOIN FUNCTION_MOD B
ON A.FUNCTION_MOD_ID = B.FUNCTION_MOD_ID
WHERE A.GROUP_MOD_ID='G02') AS TEMP
) AS SOURCE_TB
PIVOT
( ALLOW FOR FUNCTION_MOD_NAME IN (FUNCTION_MOD_NAME)
) AS PIVOT_TB
END

But it's error

Msg 156, Level 15, State 1, Procedure GET_FUNC, Line 13
Incorrect syntax near the keyword 'FOR'.


Note: Type of ALLOW is bit and rows FUNCTION_MOD_NAME is dynamic

Thank guys
   

- Advertisement -