Stored Procedure Question
-
I want to create a stored procedure where I can select with a 'where in ' and a list of integers against the integer-typed primary key. For example: PR_GetSomething @ID='0,1' Only that doesn't work since it is a varchar. Here is the ad-hoc query for what I want to do in an SP: select * from Something where ID IN (0,1) Thanks for any help....
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
-
I want to create a stored procedure where I can select with a 'where in ' and a list of integers against the integer-typed primary key. For example: PR_GetSomething @ID='0,1' Only that doesn't work since it is a varchar. Here is the ad-hoc query for what I want to do in an SP: select * from Something where ID IN (0,1) Thanks for any help....
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
-
When you are forming the string of ids itself try to include '' in that string. "0,1" -> "'0', '1',...."
Gautham
Thanks for the response but that didn't work for me. I think it is becasuse theId param in my SP is a varchar? I dunno, maybe I should use a different datatype in that param? I get this: Conversion failed when converting the varchar value ''0','1'' to data type int.
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
-
Thanks for the response but that didn't work for me. I think it is becasuse theId param in my SP is a varchar? I dunno, maybe I should use a different datatype in that param? I get this: Conversion failed when converting the varchar value ''0','1'' to data type int.
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
Ah well...I'll just make two seperate SP's. One for a specific ID and the other for all of 'em.
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.