|
Hi, Can anyone help me out with this query: The error I get is > Server: Msg 170, Level 15, State 1, > Line 5 Line 5: Incorrect syntax near > '='. The line of query where I'm assigning the descrip column to @descrip is basically to collect ALL descriptions available for a certain order in the BACK table and put it in one field separated by
(comments are locked)
|
|
You cannot select data and assign variables at the same time. If you need your results to include the list of all descrip values for the specified salesOrderNo then you cannot assign the value to the variable per returned record and expect it to somehow return correct values for each record. You can restate your query like this to get the data you need: Oleg I am on SQL SERVER 2000. Running your solutions yeields a few errors:
Feb 10 '11 at 11:17 AM
peacemaker1820
Sorry about that. This is true that the script in my answer will not run on SQL Server 2000 because the latter does not have APPLY and does not support xml like 2005 does.
Feb 10 '11 at 11:24 AM
Oleg
So, do I have to resort to a function?
Feb 10 '11 at 12:09 PM
peacemaker1820
SQL Server 2000 supports user defined scalar functions, so probably yes. If you opt to go this route then you have to write a function taking salesOrderNo as a parameter and returning the list of br-delimited values. The body of the function is pretty much what you had in your original select except you should probably use SELECT @descrip = ISNULL(@descrip + '<br/>', '') + descrip -- rather than SELECT @descrip = ISNULL(@descrip + '', '') + descrip Then of course you will replace the ocurence of @descrip in your select list with this function call. This appears to be a much better option than to revert to using a cursor. Too bad that you still have SQL Server 2000, the life is much easier when working with later versions. It is amazing that 2000 is still there when support for SQL Server 2005 ends in 2 months from now (on April 12th of this year).
Feb 10 '11 at 12:56 PM
Oleg
(comments are locked)
|
|
My Solution and it works...thanks all. I am glad to hear it works. When you upgrade to a newer version, you might consider switching to the soluition using cross apply with a table-valued function (or inline SQL like in my answer) for performance reasons because the table valued functions appear to offer better performance. In any case, please come back to this site when you have a question or willing to offer your help with answers. As you can see, it does not take long to get a reply here.
Feb 10 '11 at 01:27 PM
Oleg
True. I most definately will. Performance is my number one priority.
Feb 11 '11 at 04:59 AM
peacemaker1820
(comments are locked)
|

