| Author |
Topic |
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2010-06-08 : 09:22:28
|
How can I use variables in a Stored Procedure?I need to use the IN (....) as per my code belowHow can I run the SP using more than 1 value if needed to?ALTER PROCEDURE [dbo].[ShowFTFDataPropCount] @pContractID INTASBEGINSELECT FTF.PropID ,FTF.CountJobNoFROM tmpFTFCountJobs FTFINNER JOIN tmpProperties PON P.PropID = FTF.PropIDWHERE P.ContractID IN (@pContractID)END I get an error Msg 102, Level 15, State 1, Line 1Incorrect syntax near '74'. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-08 : 09:27:15
|
1 Use split function and join with the table2 or useALTER PROCEDURE [dbo].[ShowFTFDataPropCount] @pContractID INTASBEGINSELECT FTF.PropID ,FTF.CountJobNoFROM tmpFTFCountJobs FTFINNER JOIN tmpProperties PON P.PropID = FTF.PropIDWHERE ','+@pContractID+',' like '%,'+cast(P.ContractID as varchar(10))+',%'END MadhivananFailing to plan is Planning to fail |
 |
|
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2010-06-08 : 10:40:56
|
| Excellent, thanks.When executing the SP, do I use EXEC dbo.ShowFTFDataPropCount('74','75') as normal or another way? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-08 : 10:42:41
|
| EXEC dbo.ShowFTFDataPropCount('74,75')MadhivananFailing to plan is Planning to fail |
 |
|
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2010-06-08 : 10:54:42
|
| I tried that and got the errorMsg 102, Level 15, State 1, Line 1Incorrect syntax near '74,75'.Where has it gone wrong? |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-06-08 : 11:15:10
|
| @pContractID should be a varchar datatypeJimEveryday I learn something that somebody else already knew |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-08 : 11:16:17
|
| @pContractID should have datatype varchar(100)MadhivananFailing to plan is Planning to fail |
 |
|
|
JezLisle
Posting Yak Master
132 Posts |
Posted - 2010-06-08 : 11:19:33
|
Sorry to be a pest, but that still says Msg 102, Level 15, State 1, Line 1Incorrect syntax near '74,75'.ALTER PROCEDURE [dbo].[ShowFTFDataPropCount] @pContractID VARCHAR(100)ASBEGINSELECT FTF.PropID ,FTF.CountJobNoFROM tmpFTFCountJobs FTFINNER JOIN tmpProperties PON P.PropID = FTF.PropIDWHERE ','+@pContractID+',' LIKE '%,'+CAST(P.ContractID AS VARCHAR(100))+',%'END EXEC dbo.ShowFTFDataPropCount('74,75') |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-06-08 : 11:21:37
|
| Doh! No '(' when calling a procedureEXEC dbo.ShowFTFDataPropCount '74,75' jimEveryday I learn something that somebody else already knew |
 |
|
|
|