last day (14 days later) » 

5:39 PM
-1
Q: SQL Stored Procedure - Parameters

PigsIncorporatedI have a stored procedure that returns a grid result. I'm having some fundamental issues with transferring the stored procedures @idCC parameter to the SQL query as shown. I know the SQL works if I remove the parameter and hard code in a number value. How do I allow the query to read @idCC to the...

 
replace WHERE dbo.CC_Contacts.idCC = '''+@idCC+''' with WHERE dbo.CC_Contacts.idCC = + @idCC
 
The row looks like: |idCC|GroupName1|GroupName2|GroupName3| with values like |25|Null|X|Null|X|
 
is the error solved?
 
No, the SQL command is in quotes, you have to escape the quotes in order to read the parameter. I think.
 
can you print the @sql and paste here
 
5:39 PM
SELECT dbo.CC_Contacts.idCC, dbo.CC_Groups.GroupName AS gName, 'X' AS IsInGroup FROM dbo.CC_ContactGroups INNER JOIN dbo.CC_Groups ON dbo.CC_ContactGroups.idGroup = dbo.CC_Groups.idGroup INNER JOIN dbo.CC_Contacts ON dbo.CC_ContactGroups.idCC = dbo.CC_Contacts.idCC WHERE dbo.CC_Contacts.idCC = '25' ) AS x PIVOT ( MAX(IsInGroup) FOR gName IN([GroupName1],[GroupName2],[GroupName3],[GroupName4],[Grou‌​pName5],[GroupName‌​6]‌​) ) as p' to data type int.
I changed the @idCC to 25 for the print of the SQL
 
hi
dont use static value 25 print the query with input param
 
SELECT dbo.CC_Contacts.idCC, dbo.CC_Groups.GroupName AS gName, 'X' AS IsInGroup
FROM dbo.CC_ContactGroups INNER JOIN
dbo.CC_Groups ON dbo.CC_ContactGroups.idGroup = dbo.CC_Groups.idGroup INNER JOIN
dbo.CC_Contacts ON dbo.CC_ContactGroups.idCC = dbo.CC_Contacts.idCC
WHERE dbo.CC_Contacts.idCC = '' to data type int.
it leaves it blank, can't see the @idCC parameter
 
yes can you show me the statement for executing stored procedure
 
This?
DECLARE @return_value int

EXEC @return_value = [dbo].[sp_CC_ContactGroupList]
@idCC = 22

SELECT 'Return Value' = @return_value

GO
 
replace dbo.CC_Contacts.idCC = '''+cast(@idCC as varchar)+'''
now it will show you @idCC
 
5:50 PM
You are a genius. It works perfectly!
 
i am posting that as answer
great
i have posted
 

last day (14 days later) »