L
Lloyd Dupont
I'm trying to write a stored procedure which try to write some text and
return the new ID or -1 if the text was already there.
something along those lines:
Table: BugReport
------------------
ID: int, identity/auto-increment
Text: nvarchar(max)
create bool Procedure(nvarchar(max) bugText)
{
if( count( select * from BugReport where Text = bugText) )
return -1;
int ret;
insert into BugReport ( Text ) values ( BugReport ); select ret =
@@lastrowid;
return ret;
}
How would you write this in real/valid TSQL ?
Thanks!
return the new ID or -1 if the text was already there.
something along those lines:
Table: BugReport
------------------
ID: int, identity/auto-increment
Text: nvarchar(max)
create bool Procedure(nvarchar(max) bugText)
{
if( count( select * from BugReport where Text = bugText) )
return -1;
int ret;
insert into BugReport ( Text ) values ( BugReport ); select ret =
@@lastrowid;
return ret;
}
How would you write this in real/valid TSQL ?
Thanks!