print sql-server | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

print sql-server

hello: i have this huge problem. it’s killing me.i have this store procedure :
CREATE PROCEDURE siesta @param1 int AS declare @ne1 varchar(20)
declare @text varchar(20) if( select count(*) from tabla3 where [email protected])<1
begin select @ne1=(select campo2 from tabla3 where [email protected])
insert into tabla3 values(@param1,@ne1)
end
else
begin print ‘already in the table’
end
GO
the procedure insert if it’s not there . and if the person is already in the table send a message. the problem is that i want to call the store procedure from visual basic 6.0
but i want to see the PRINT ‘already in the table’. how can i do it? i’ve tried several things but … . THANK YOU FOR YOUR HELP.
SELECT ‘Already in the table.’ MeanOldDBA
[email protected] When life gives you a lemon, fire the DBA.
or RAISERROR(‘Already in table’, 16, 1) and then have VB handle the exception thrown by ADO
RAISERROR and ADO is ideal for this. The SELECT ‘Already in Table’) has a chance of not being seen by the front-end developer for what it is – an constraint violation. The developer may actually use it as a recordset (VB 6) or datareader (VB.NET) and end up writing more code to handle this situation. Does this feel like a UNIQUE constraint? If it looks, smells and works like a UNIQUE constraint, then please define one and let SQL Server do the work for you.
Otherwise , you may also want to re-write your stored procedure thus: CREATE PROCEDURE siesta
@param1 int
AS
Declare @ne1 varchar(20) IF EXISTS( Select campo1 from tabla3 where [email protected])
RAISERROR (‘Already in table’, 16, 1)
ELSE
BEGIN
Select @ne1=(select campo2 from tabla3 where [email protected])
Insert into tabla3 values(@param1,@ne1)
END GO
Nathan H.O.
Moderator
SQL-Server-Performance.com
THANK YOU , THANK YOU VEEEEEEEERRRRRRRYYYYYYYYY MUCH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
]]>