Monday, March 12, 2012

Invalid column name for the value of a column

I am having a SQl satement as
If(Object_ID('DBName.Dbo.##TEMPDelete')) is not null
Drop table ##TEMPDelete
SET @.Name = (Select replace(@.Name,' ','_'))
Set @.SQL = 'Select top 1 Address as AddressTemp into ##TEMPDelete from '+ @.Name + ' where eid = '+ @.eid
Exec (@.SQL)
Set @. Name = (select @.Name from ##TEMPDelete)
Print AddressTemp
this results back as an error
Invalid Column name EMP123 (the Value of @.eid instead of the column eId)
samay
please adviceI don't see where @.eid is getting valued. Assuming that it is a char
variable - I would think that you want the select statement to be:
Set @.SQL = 'Select top 1 Address as AddressTemp into ##TEMPDelete from '+
@.Name + ' where eid = '''+ @.eid +''''
So that it puts quotes around the value of @.eid
--TJTODD
"KritiVerma@.hotmail.com" <KritiVermahotmailcom@.discussions.microsoft.com>
wrote in message news:EBA43F13-84EB-42A0-9635-3AD2840C78F8@.microsoft.com...
> I am having a SQl satement as
> If(Object_ID('DBName.Dbo.##TEMPDelete')) is not null
> Drop table ##TEMPDelete
> SET @.Name = (Select replace(@.Name,' ','_'))
> Set @.SQL = 'Select top 1 Address as AddressTemp into ##TEMPDelete from '+
@.Name + ' where eid = '+ @.eid
> Exec (@.SQL)
> Set @. Name = (select @.Name from ##TEMPDelete)
> Print AddressTemp
>
> this results back as an error
> Invalid Column name EMP123 (the Value of @.eid instead of the column eId)
> samay
> please advice|||Well, where are your single quotes? eid is a string, right? Try
Set @.SQL = 'Select top 1 Address as AddressTemp into ##TEMPDelete from '+
@.Name + ' where eid = '''+ @.eid +''''
--
http://www.aspfaq.com/
(Reverse address to reply.)
"KritiVerma@.hotmail.com" <KritiVermahotmailcom@.discussions.microsoft.com>
wrote in message news:EBA43F13-84EB-42A0-9635-3AD2840C78F8@.microsoft.com...
> I am having a SQl satement as
> If(Object_ID('DBName.Dbo.##TEMPDelete')) is not null
> Drop table ##TEMPDelete
> SET @.Name = (Select replace(@.Name,' ','_'))
> Set @.SQL = 'Select top 1 Address as AddressTemp into ##TEMPDelete from '+
@.Name + ' where eid = '+ @.eid
> Exec (@.SQL)
> Set @. Name = (select @.Name from ##TEMPDelete)
> Print AddressTemp
>
> this results back as an error
> Invalid Column name EMP123 (the Value of @.eid instead of the column eId)
> samay
> please advice

No comments:

Post a Comment