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.
| Author |
Topic |
|
x-jeno
Starting Member
6 Posts |
Posted - 2011-07-20 : 21:44:15
|
| HiAnother 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] |
 |
|
|
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 nowDim myCols As String = "id, usn, pwd""SELECT " & myCols & " FROM Staff WHERE " & colName & " LIKE '%" & searchTru & "%'"I know this kind of method for asking valuescreate procedure newStaff (@staffID VARCHAR(10), @staffName VARCHAR(20)) As INSERT INTO Staff staffID, staffName) VALUES (@staffID, @staffName)But how so for a column name? |
 |
|
|
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 thishttp://www.sommarskog.se/dynamic_sql.html KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
x-jeno
Starting Member
6 Posts |
Posted - 2011-07-21 : 07:18:00
|
| ic thanks, i will go check it out |
 |
|
|
|
|
|
|
|