Click here to Skip to main content
16,016,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi
how can i write this stored procedure into simple query
SQL
UPDATE Con
SET Category1code =c1.Category1Name, Category2Code=c2.Category2Name
FROM Contacts Con 
    INNER JOIN Category1 As c1
        ON Con.Category1Code = c1.Category1Code
    Inner Join Category2 As c2
        ON Con.Category2Code = c2.Category2Code;

thanx in advance
Posted
Updated 18-Mar-13 23:25pm
v2
Comments
gvprabu 19-Mar-13 5:19am    
Hi Check in Google... :-)

1 solution

Hi...

SQL
CREATE PROCEDURE dbo.UpdCategory
AS
BEGIN
    BEGIN TRY
	   BEGIN TRANSACTION tnUpdCategory
		  UPDATE Con
		  SET Category1code =c1.Category1Name, Category2Code=c2.Category2Name
		  FROM Contacts Con
		  INNER JOIN Category1 As c1
		  ON Con.Category1Code = c1.Category1Code
		  Inner Join Category2 As c2
		  ON Con.Category2Code = c2.Category2Code;
	   COMMIT TRANSACTION tnUpdCategory
    END TRY
    BEGIN CATCH
	   IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION tnUpdCategory
	   PRINT ERROR_MESSAGE()
    END CATCH
END
 
Share this answer
 
Comments
Ajinkya Ban 19-Mar-13 5:26am    
thanx but i want to write it without stored procedure
gvprabu 19-Mar-13 5:28am    
Without SP means, Direct Query right...
What is the actual problem u are facing now..?
Ajinkya Ban 19-Mar-13 5:31am    
yes i want direct query.
because in my project i m not using SP.
gvprabu 19-Mar-13 5:32am    
Then your Query is correct right....
Ajinkya Ban 19-Mar-13 5:34am    
yes just i want replace it without SP into direct query

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900