| Author |
Topic |
|
sujeethbala2110
Starting Member
29 Posts |
Posted - 2006-09-24 : 06:54:27
|
| what is the problem with this programe. its giving an error'incorrect syntax near @flag'CREATE PROCEDURE spUpdateStock@flag varchar(70)ASBEGINif exists(Select fld1 from table1 where fld1=Convert(varchar,Getdate(),101))( set @flag="asdsdfsaf" exit)else statemet 1--multiple insert statement followsENDGOsuji |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-09-24 : 08:42:26
|
| CREATE PROCEDURE spUpdateStockYou should prefix spUpdateStock by the owner - e.g. "dbo."@flag varchar(70)A parameter called "flag" seems unlikely to have a datatype of 70 charactersASBEGINif exists(Select fld1 from table1 where fld1=Convert(varchar,Getdate(),101))You should specify the width of the VARCHAR in "Convert(varchar,Getdate(),101)"You should use "SELECT *" and not "SELECT fld1"(You don't use brackets after IF EXIST, you need to use BEGIN / ENDset @flag="asdsdfsaf"exitThere is no such keyword EXIT)elsestatemet 1If "statemet 1" is a SProc call you need to use EXEC--multiple insert statement followsif this multiple insert statement is intended to be part of the ELSE, rather than only "statemet 1", then you need to surround it with BEGIN / END (good practice anyway, even if its a single statement)ENDGOLots of basic mistakes here, looks like you need some basic instruction - a book, course or some of the beginner material on the Internet.Kristen |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2006-09-24 : 08:43:04
|
after your if statement should come the begin and end block ieCREATE PROCEDURE spUpdateStockASdeclare @flag varchar(70)if exists(Select fld1 from table1 where fld1=Convert(varchar,Getdate(),101))BEGINset @flag="asdsdfsaf"endelsestatemet 1 also if you are setting the value of @flag in your code then it would be better to declare this variable at runtime rather than as a parameter to be passed in, something like above |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-09-24 : 08:43:39
|
[code]if exists(Select fld1 from table1 where fld1=Convert(varchar,Getdate(),101))begin set @flag = 'asdsdfsaf' -- use single quote not double quote exit returnend[/code] KH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-09-24 : 10:16:24
|
 KH |
 |
|
|
sujeethbala2110
Starting Member
29 Posts |
Posted - 2006-09-24 : 10:57:40
|
| ya i am new to sql. thanks for reply.suji |
 |
|
|
sujeethbala2110
Starting Member
29 Posts |
Posted - 2006-09-24 : 11:48:49
|
| where i will get the beginner meterial. please give me some ref.suji |
 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2006-09-24 : 14:10:00
|
| excellent resource: BOOKS ONLINE, press the F 1 KeyAlso google is your friendhttp://www.google.com/search?hl=en&q=learn+ms+sql |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-09-24 : 21:26:39
|
| Search for Ken Henderson and buy everything written by him.http://www.amazon.com/s/ref=br_ss_hs/002-8022302-4782405?platform=gurupa&url=index%3Dblended&keywords=ken+hendersonMeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|