July 28, 2011 at 12:33 pm
I am passing a list for my parameter like this: 'TW'''',''''MO'''',''''DA'''',''''FM'
I am then doing a where statement in my query like this:
WHERE Code IN(''''' + CONVERT(varchar(8000),@Code) + ''''')
This returns the results in the order it finds it: FM, MO, TW, DA.
How would I get the result in the order that the parameters were passed? TW, MO, DA, FM
July 28, 2011 at 12:54 pm
If you want results in a certain order you have to use an order by. Looking at the very sparse bit of information you have provided it does not seem like you would have a column that would work as a sort order. The only way you would be able to do is to use something like Jeff Moden's CSV splitter[/url]. This would let you assign a when you actually split your input so you could return it in the same order it was received.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 12:58 pm
I could add an order column, and I have a split string function that I use. When I split the string how do I assign it a value for the order column?
July 28, 2011 at 1:12 pm
You might want to read the best practices link on how to post questions.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
July 28, 2011 at 1:15 pm
I provided all the information in the query that pertains to my problem...
July 28, 2011 at 1:16 pm
btull89 (7/28/2011)
I could add an order column, and I have a split string function that I use. When I split the string how do I assign it a value for the order column?
You would do it in you split function. My guess is the one that Jeff created will blow the doors of another home cooked split function for performance. It is insanely fast!!! The added benefit is that is splits it into a table so you could get a row_number() at the same time you split it.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 1:17 pm
btull89 (7/28/2011)
I provided all the information in the query that pertains to my problem...
Well except for any details about how you split your string. That is the root of where your problem is located. Not saying there is anything wrong with the method of how you split but that is where you will have to add your order by logic.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 2:24 pm
My solution: I found a way to pass the values individually in the parameter and went from there.
July 28, 2011 at 2:27 pm
Cool glad you figured out a way to solve it.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 2:30 pm
Sean, I didn't realize you posted two more replies before your last one. I completely missed it somehow.
Thank you very much for helping me.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply