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 |
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2006-11-22 : 03:25:34
|
| can anybody tell me how to use COALESCE function in inner query? here is my sql statement...DECLARE @EmpID VARCHAR(100)SELECT ....,(SELECT @EmpID = COALESCE(CONVERT(VARCHAR(100), @EmpID) + ', ', '') + CAST(Emp_ID AS VARCHAR(15)) FROM USER_MSTR WHERE User_ID IN ( SELECT User_ID FROM USER_DTL WHERE CO_ID = Com.CO_ID GROUP BY User_ID) AS Emp_ID...FROM ...when i run this sql it showing me this error"Incorrect syntax near '='." whats wrong with syntax? thanks in advance,Mahesh |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-22 : 03:29:38
|
| Remove @EmpID = to begin with.Peter LarssonHelsingborg, Sweden |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2006-11-22 : 04:19:59
|
| thanks Peso, is it possible to do without using any function, or can't we did it in single sql statement? I have already one function which convert Rows into Column(Comma separated values). When i learn about COALESCE function, i tried this with single sql, its working fine. Now i wants to implement it in my one of the inner query.Mahesh |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-22 : 04:48:02
|
| Not the way you want it, as a subquery.Think about what will happen for netx row. @EmpID will already be initialized with a value...Peter LarssonHelsingborg, Sweden |
 |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2006-11-22 : 04:51:02
|
| thanks Peso, i didn't considered the case. thank u very much. so it means i have to use function for this.well, i will.Mahesh |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|
|
|
|