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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating Stored Procedure based on user input

Author  Topic 

ktimov1
Starting Member

6 Posts

Posted - 2010-07-29 : 10:29:44
Hello,

I need help creating a stored procedure which will output a count based on user inputs from VB or C# app.

For example:
user will input a field name and a value from textboxes and then the stored procedure will run:

SELECT COUNT(*) FROM table WHERE txtField = txtValue

Finally the count result will be posted to them.

Any ideas on how I can accomplish this

Devart
Posting Yak Master

102 Posts

Posted - 2010-07-29 : 12:20:30
Hello,

You can try this:

create procedure <your_procedure_name>
(@table varchar(<your_size>),@field_name varchar(<your_size>),@field_value varchar(<your_size>))
as
set nocount on
declare @sql varchar(8000)
set @sql='SELECT COUNT(*) FROM '+@table+' WHERE '+@field_name+' = '+char(39)+@field_value+char(39)
exec (@sql)

Best regards,

Devart Team
Go to Top of Page
   

- Advertisement -