Sunday, 25 February 2018

Example of Table variable in Sql Server

1.Creating Table Variable:

DECLARE @Posted_Split TABLE (
Post_Site INT
,Post_Type TINYINT
)

2.Inserting data into Table Variable:

INSERT INTO @Posted_Split
select 2,0

3.To view data of Table Variable:

select Post_Site,Post_Type from @Posted_Split


4.Joining with Table Variable:

UPDATE tblJobPostData set JobPost_ID=450,Post_Type=PS.Post_Type,Post_Site=PS.Post_Site,IsProcessed=0
from tblJobPostData JP inner join @Posted_Split PS on PS.Post_Type=JP.Post_Type and PS.Post_Site=JP.Post_Site
where JP.jobpost_id=450

No comments:

Post a Comment