Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamic Where Clause In Stored Procedure
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00634614
Message ID:
00637189
Views:
28
>I think Sergey gave you the best answer.
>
>BTW, what are you using the row counts for?
>
>-Mike

Thanks Mike,
Sergey's answer confirmed my findings. The query I presented in the example was oversimplified. There is a WHERE clause attached to it. We have several tables (each with its own structure) that we require counts of available records based on several criteria. The user selects the criteria from a VFP interface, which then creates the SQL command and executes it on the selected table. My dilemma is that "both" the table and the WHERE clause are variables. I could write a usp for each table, but that would make maintenance a bit complex. Is there a way to execute a query with a fixed table but a variable WHERE clause without EXEC(@SQLcmd)?

SELECT COUNT(*)
FROM Publishers
WHERE @myClause

Thank you,
Aristotle
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform