Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Exec procedure with "MERGE USING" statement

Author  Topic 

MikeSamteladze
Starting Member

2 Posts

Posted - 2011-11-21 : 04:44:47
I'm trying to do something like this:

MERGE master.dbo.sysmessages SM
USING (SELECT SystemID, DisplayMessage FROM ErrorMessages) NR ON SM.error = NR.SystemID
WHEN NOT MATCHED THEN
BEGIN
EXEC sp_addmessage @msgnum = NR.SystemID,@severity = 16,@msgtext = NR.DisplayMessage
END;
Isn't it possible without cursor?

thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-21 : 04:50:46
i think you cant use MERGE like this. you need call sp in a loop and insert each new error message in it



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

MikeSamteladze
Starting Member

2 Posts

Posted - 2011-11-21 : 05:02:51
This is the only solution for me now, but I'll keep search the way without loop.

Thanks
Go to Top of Page

johntech
Yak Posting Veteran

51 Posts

Posted - 2011-11-24 : 09:44:22
I'm not sure ,but I thought that below code may be useful

MERGE master.dbo.sysmessages SM
if (SELECT SystemID, DisplayMessage FROM ErrorMessages) NR ON SM.error != NR.SystemID
THEN
BEGIN
EXEC sp_addmessage @msgnum = NR.SystemID,@severity = 16,@msgtext = NR.DisplayMessage
END;
Go to Top of Page
   

- Advertisement -