i have the following select
that tests if specific schema with specific table name has specific column
Declare @ColumnName nvarchar(255)
Declare @ColumnType nvarchar(255)
Declare @ColumnLength nvarchar(255)
Declare @DataBaseName nvarchar(255)
SELECT @ColumnName=COLUMN_NAME,@ColumnType=DATA_TYPE,@ColumnLength=CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
and COLUMN_NAME = @ColumnName and TABLE_SCHEMA=@DataBaseName
My Problem is that the variables must be quoted in select statement and if i put the statement in a string and then executes the string as a solution @ColumnName,@ColumnType,@ColumnLength will not have value unless i put them as out parameters and i tried this way recently but it didnt work
is there any way
to handle that cause this problem always faces me and put me in a state of hopless
Sorry i didnt discribe in a good way i mean by quoted variables
the variables in where clause
i will write the query agian
Collapse | Copy Code
Declare @ColumnName nvarchar(255)
Declare @ColumnType nvarchar(255)
Declare @ColumnLength nvarchar(255)
Declare @DataBaseName nvarchar(255)
Declare @x nvarchar(255)
SELECT @x=COLUMN_NAME,@ColumnType=DATA_TYPE,@ColumnLength=CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = @TableName
and COLUMN_NAME = @ColumnName and TABLE_SCHEMA=@DataBaseName
the variables @TableName ,@ColumnName,@DataBaseName must be quoted
Suppose i must write the following query
SELECT @x=COLUMN_NAME,@ColumnType=DATA_TYPE,@ColumnLength=CHARACTER_MAXIMUM_LENGTH
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TableA'
and COLUMN_NAME = 'ColumnA' and TABLE_SCHEMA='DataBaseA'
so my question is how can i quote the variables in where statement without writing query statement in string which leads me to put the variables in select statement as out variables
i mean i need the variables in where string to be parsed with double quotation