| Author |
Topic |
|
BCJ
Starting Member
42 Posts |
Posted - 2008-06-19 : 09:01:14
|
| select field1 from table1 where field1 = @p_field1Msg 137, Level 15, State 2, Line 1Must declare the scalar variable "@p_field1".Hi, i'm getting this error, could anybody please explain, how the syntax should be.........thanks |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-06-19 : 09:03:31
|
| you require to declare the variable with the name @p_field1Chiraghttp://www.chirikworld.com |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2008-06-19 : 09:04:08
|
I think its pretty obvious what the error and what corrective action is needed from your end.Declare @p_field1 <data_type>set @p_field1 = <some_value>select field1 from table1 where field1 = @p_field1 Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
BCJ
Starting Member
42 Posts |
Posted - 2008-06-19 : 09:22:07
|
| Thanks to all , also would like to know , how can i pass the parameter values at run time instead of doing "set @p_field1 = <some_value>" . is it possible without creating a procedure ..... |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2008-06-19 : 09:50:20
|
| No you can not pass the parameters values at run time ... without using sps or udfsDo you mean that you require to fetch the value from the some table ? Select @p_Field = Column_name from yourtableChiraghttp://www.chirikworld.com |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 10:19:53
|
quote: Originally posted by BCJ Thanks to all , also would like to know , how can i pass the parameter values at run time instead of doing "set @p_field1 = <some_value>" . is it possible without creating a procedure .....
DIdnt understand what you're asking. If you're question was whether you could use variables without declaring answer is no. |
 |
|
|
BCJ
Starting Member
42 Posts |
Posted - 2008-06-19 : 12:12:25
|
| Thanks , that's what i was looking for , but just confirming that after executing this statement "select field1 from table1 where field1 = @p_field1"it should ask me to enter the value for p_field1,so, i can enter as my wish.........is it possible ...thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 12:14:09
|
quote: Originally posted by BCJ Thanks , that's what i was looking for , but just confirming that after executing this statement "select field1 from table1 where field1 = @p_field1"it should ask me to enter the value for p_field1,so, i can enter as my wish.........is it possible ...thanks
Nope. Unfortunately you cant have SQL Server prompt for user input. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 12:16:01
|
| However you could create a procedure with the statement like thisCREATE PROC YourProc@p_field1 datatypeASselect field1 from table1 where field1 = @p_field1GOand then call this with value you likeYourProc <value1>YourProc <value2>... |
 |
|
|
|