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.
| Author |
Topic |
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2008-07-08 : 17:43:33
|
| In the following stored procedure, the column CompanyNum is a numeric type. If I pass in multiple company numbers, how do I change the value of @CompNo '1,5,7' to numeric? In the following SQL statement, the where clause is "WHERE CompanyNum in ('1,5,7')". It should be "WHERE CompanyNum in (1,5,7)"ALTER PROCEDURE [dbo].[procFillControls] @CompNo as nvarchar = ''AS SELECT DISTINCT BusinessUnitCode FROM BusinessTable WHERE CompanyNum in (@CompNo)Thanks.DY |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-07-08 : 18:00:37
|
| One popular way to do this is to create a table valued function that parses the csv into rows. You can then JOIN to the function as you would a table. Look at the section that starts with "CSV" in this thread and follow the links:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210Be One with the OptimizerTG |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-09 : 00:12:10
|
| [code]ALTER PROCEDURE [dbo].[procFillControls]@CompNo as nvarchar = ''ASSELECT DISTINCT BusinessUnitCodeFROM BusinessTableWHERE ','+ @CompNo + ',' LIKE '%,'+CAST(CompanyNum AS varchar(10))+',%'[/code] |
 |
|
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2008-07-09 : 11:46:22
|
quote: Originally posted by visakh16
ALTER PROCEDURE [dbo].[procFillControls]@CompNo as nvarchar = ''ASSELECT DISTINCT BusinessUnitCodeFROM BusinessTableWHERE ','+ @CompNo + ',' LIKE '%,'+CAST(CompanyNum AS varchar(10))+',%'
It still didn't get data. Why do you add ','? Thanks. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-09 : 11:49:37
|
quote: Originally posted by danyeung
quote: Originally posted by visakh16
ALTER PROCEDURE [dbo].[procFillControls]@CompNo as nvarchar = ''ASSELECT DISTINCT BusinessUnitCodeFROM BusinessTableWHERE ','+ @CompNo + ',' LIKE '%,'+CAST(CompanyNum AS varchar(10))+',%'
It still didn't get data. Why do you add ','? Thanks.
because you parameter value is comma delimited. b/w did you get any error? what was full query used? and also can you provide some data from table? |
 |
|
|
danyeung
Posting Yak Master
102 Posts |
Posted - 2008-07-09 : 14:22:57
|
| It was resolved. Please see this link: http://forums.asp.net/t/1287505.aspx |
 |
|
|
|
|
|
|
|