| Author |
Topic |
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2006-10-10 : 00:48:23
|
| hello friends!!i am trying to create stored procedure but i am getting error create proc t@i intasif @i = 1beginselect s Name,identity (int,1,1) as intid into #Tfrom (select 'SS' s) pendif @i = 2beginselect s Name,identity (int,1,1) as intid into #Tfrom (select 'S' s) pendServer: Msg 2714, Level 16, State 1, Procedure t, Line 15There is already an object named '#T' in the database.Server: Msg 170, Level 15, State 1, Procedure t, Line 17Line 17: Incorrect syntax near 'p'.T.I.A |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-10 : 00:53:32
|
| Create #T first, before all IFs.Peter LarssonHelsingborg, Sweden |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-10 : 01:02:34
|
You can't have more than one insert into statement that create the same temp table. As Peter suggested create the temp table first or use different temp table name KH |
 |
|
|
under2811
Constraint Violating Yak Guru
366 Posts |
Posted - 2006-10-10 : 01:26:48
|
| hello ppls..thanks for ur kindness!!!!!! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-10 : 09:28:27
|
| It is parsing errorMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-10-10 : 09:36:13
|
Parsing error?create proc t@i intasif @i = 1beginselect s Name,identity (int,1,1) as intid into #T1from (select 'SS' s) pendif @i = 2beginselect s Name,identity (int,1,1) as intid into #T2from (select 'S' s) pend works well...Peter LarssonHelsingborg, Sweden |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-10-10 : 09:53:17
|
| I think it's some kind of weird bug...why can't it allow to create temp table based on two different conditions? There is no chance of creating same table twice..I mean syntactically there is no error !Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2006-10-10 : 10:09:03
|
....and this is an exercise in?create proc t@i intasDECLARE @T table ([Name] char(2), intid int IDENTITY(1,1))IF @i = 1 INSERT INTO @T([Name]) SELECT 'SS'IF @i = 2 INSERT INTO @T([Name]) SELECT 'S'SELECT * FROM @TGOEXEC t 1GOEXEC t 2GODROP PROC tGO Futility? Want to give us what you are really going for?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-10-10 : 10:10:36
|
| Peso, use #T1 in two conditionsMadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2006-10-10 : 10:12:36
|
| Yes we all se that the sproc reacts as though you are trying to create 2 temp tables on compile.There's is no need to worry about trans logging for one row. He should just use a table variable.And until they tell us what they really want, the code is rather meaninglessBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|