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
 output parameters for column name

Author  Topic 

x-jeno
Starting Member

6 Posts

Posted - 2011-07-20 : 21:44:15
Hi
Another question regarding column.
I am trying to create a stored procedure which will ask for the column name and a value under it but I am stuck at this part.
I do know how to create a normal one asking for values but how do you do it for asking a column name input?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-20 : 21:52:15
stored procedure cannot "ask" for value. That's the job of your front end application. You accept the input value and then pass to the stored procedure for processing


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

x-jeno
Starting Member

6 Posts

Posted - 2011-07-20 : 22:07:56
Well, yes, I can accept the input value from my front end application and pass it to SP but I am trying to find 1 for "asking" a column name.
Sorry if this sounds confusing. I do not know the terms well enough to explain my problem properly.

My sql query in my front end is something like this right now
Dim myCols As String = "id, usn, pwd"
"SELECT " & myCols & " FROM Staff WHERE " & colName & " LIKE '%" & searchTru & "%'"


I know this kind of method for asking values
create procedure newStaff (@staffID VARCHAR(10), @staffName VARCHAR(20))
As
INSERT INTO Staff staffID, staffName)
VALUES (@staffID, @staffName)

But how so for a column name?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-20 : 22:25:54
for column name it is just string. If you are passing in column name to the stored procedure, you will required to use Dynamic SQL. Take a look at the this

http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

x-jeno
Starting Member

6 Posts

Posted - 2011-07-21 : 07:18:00
ic thanks, i will go check it out
Go to Top of Page
   

- Advertisement -