Below is the query used,
drop table Customers
CREATE TABLE Customers
(
Cus_ID int PRIMARY KEY ,
Cus_Name varchar(30) NOT NULL,
Cus_City varchar(30) NOT NULL,
Cus_Country varchar(30) NOT NULL
)
insert into customers values(1,'venkat','dpi','india')
DECLARE @SQL varchar(1000)
declare @cus_name varchar(1000)
declare @Cus_City varchar(1000)
declare @Cus_Country varchar(1000)
set @Cus_Name ='venkat'
SET @SQL = 'SELECT Cus_Name, Cus_City, Cus_Country FROM Customers '
SET @SQL = @SQL + 'WHERE '
SET @SQL = @SQL + 'Cus_Name = ' + @Cus_Name
EXEC(@SQL)
I got a strange SQL Server error, Invalid column name 'venkat'. But am giving column value, why it's throwing column name error. Strange !!!!
To over come this error, we need to change the value given in the set statement.
drop table Customers
CREATE TABLE Customers
(
Cus_ID int PRIMARY KEY ,
Cus_Name varchar(30) NOT NULL,
Cus_City varchar(30) NOT NULL,
Cus_Country varchar(30) NOT NULL
)
insert into customers values(1,'venkat','dpi','india')
DECLARE @SQL varchar(1000)
declare @cus_name varchar(1000)
declare @Cus_City varchar(1000)
declare @Cus_Country varchar(1000)
set @Cus_Name ='''venkat'''
SET @SQL = 'SELECT Cus_Name, Cus_City, Cus_Country FROM Customers '
SET @SQL = @SQL + 'WHERE '
SET @SQL = @SQL + 'Cus_Name = ' + @Cus_Name
EXEC(@SQL)
Thanks and Regards,
Venkatesan Prabu .J
2 comments:
Hi Venkat, This is Selva from CTS,Bangalore.
Myself,my friends and my colleagues are regular readers of your blog. Your posts are very very informative.
It would be really useful if you post more articles on SSIS, like real time examples,scenarios,Issues faced, solutions,best practises and so on.
Keep posting Bro!!!
Regards,
selva
(selva.v.kumar@gmail.com)
Sure Selva, I will do my level best in sharing my knowledge. You can see lot more articles in a couple of months from a dedicative blog writer :-)
Post a Comment