Friday, February 24, 2012

DELETE SQL Query Question - Joining a Table data type and a User Table.

Dear All,
Can anyone help me to run this below query ?
DELETE @._TCTableTemp FROM @._TCTableTemp , Scrip WHERE
@._TCTableTemp.Scrip_Code = Scrip.Scrip_Code
AND Scrip.Inst_Code LIKE 'N%' AND TC_CODE = 'STT'
The error that I am getting is:
Server: Msg 137, Level 15, State 2, Procedure STP_FORMATCCHARGE1, Line 360
Must declare the variable '@._TCTableTemp'.
Here @._TCTableTemp - Is a Table data type and Scrip is a User Table.
Thanks and Regards,
PeriPeri wrote:
> Dear All,
> Can anyone help me to run this below query ?
> DELETE @._TCTableTemp FROM @._TCTableTemp , Scrip WHERE
> @._TCTableTemp.Scrip_Code = Scrip.Scrip_Code
> AND Scrip.Inst_Code LIKE 'N%' AND TC_CODE = 'STT'
> The error that I am getting is:
> Server: Msg 137, Level 15, State 2, Procedure STP_FORMATCCHARGE1, Line 360
> Must declare the variable '@._TCTableTemp'.
> Here @._TCTableTemp - Is a Table data type and Scrip is a User Table.
> Thanks and Regards,
> Peri
Use an alias:
DELETE T
FROM @._TCTableTemp AS T, Scrip
WHERE T.scrip_code = Scrip.scrip_code
AND Scrip.inst_code LIKE 'N%'
AND tc_code = 'STT' ;
The table variable is only a temporary structure so in many cases I
wouldn't bother to delete from it. Just ignore the rows you planned to
delete.
David Portas
SQL Server MVP
--

No comments:

Post a Comment