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 |
|
khalik
Constraint Violating Yak Guru
443 Posts |
Posted - 2009-02-17 : 05:32:45
|
| Hi GuysLook like i am getting stuck with basic issues.i have SP which takes comma sperated string as parameter. the parameter has the customer names.in my SP i am trying to use the parameter and return customer total sale value.CustomerId is int and @CustomerRange is varcharselect @@CustomerRange=COALESCE(@@CustomerRange+',','')+ cast(CustomerID as varchar) from Customer where Customer name in('a','b,'c')select customerID,sum(SalVal) from CustomerSales where cast(CustomerId as varchar) in(@CustomerRange)i get no records. is some thing i am missing========================================Project Manager who loves to code.===============Ask to your self before u ask someone |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-17 : 05:38:23
|
| try like thisselect customerID,sum(SalVal) from CustomerSales where '%,' + @CustomerRange+ ',%' LIKE '%,' + CAST( CustomerId AS VARCHAR(255)) +',%' group by customerid |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
Posted - 2009-02-17 : 05:47:42
|
| Try this.exec('select customerID,sum(SalVal) from CustomerSales where cast(CustomerId as varchar) in('+@CustomerRange+')')Karthik |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-17 : 06:50:57
|
| slight modification to karthik,exec('select customerID,sum(SalVal) from CustomerSales where cast(CustomerId as varchar) in('+@CustomerRange+')group by customerid')but it is better to avoid using dynamically........ |
 |
|
|
khalik
Constraint Violating Yak Guru
443 Posts |
Posted - 2009-02-17 : 07:04:11
|
| thanks bklr========================================Project Manager who loves to code.===============Ask to your self before u ask someone |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-17 : 07:06:16
|
quote: Originally posted by khalik thanks bklr========================================Project Manager who loves to code.===============Ask to your self before u ask someone
ur welcome |
 |
|
|
|
|
|
|
|