Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Delimited string parsing question
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00667270
Message ID:
00667292
Views:
22
>Hi,
>
>I am in the process of writing a stored procedure that will be doing the preprocessing for a few of the huge reports our system generates. Rather than sucking 20,000 records into an ADO recordset and doing the sorting, filtering, grouping, etc - at the client - it seems to make more sense to do all of that in a SP and return a much smaller recordset to the client.
>
>For a certain report in this system, administrative users can select certain cost centers to run a report for. The client app will have to send this info as a parameter to the SP in a comma delimited string ( i.e. '2010,1110,3340,5560').
>
>I'm thinking that the best approach is to parse this string into a 'table' variable, then select the records into a cursor and proceed to loop through the cursor and do the processing.
>
>My question is this: Not being an expert with the built-in SQL functions, what is the best way to parse a string such as mentioned above, and populate my 'table' variable.
>
>Any assistance would be appreciated.
>
>Regards,
>
Al

You can use dynamically constructed statement like this:

CREATE PROC MY_CALCULATIONS
@cost_center_list
AS
DECLARE @select_stat_str varchar(300)
Set @select_stat_str = ‘select * from My_Table where INLIST(Cost_Center_Number,’+
@cost_center_list + ‘)’
EXECUTE (@select_stat_str)
Venelina Jordanova

Outsourcing IT Services Ltd.
Previous
Reply
Map
View

Click here to load this message in the networking platform