all groups > sql server programming > april 2007 >
You're in the

sql server programming

group:

column



Re: column Michael MacGregor
4/23/2007 4:02:56 PM
sql server programming: No such datatype.

Try something like this instead, substitute the datatype of your column for
the datatype of the variable:

DECLARE @intSearchValue INT

SET @intSearchValue = 1

SELECT *
FROM Users
WHERE SearchColumn = @intSearchValue

Will this suit your needs or are you trying to do something else? If
something else then please provide more details about what you are trying to
do.

Michael MacGregor
Database Architect

column Hrvoje
4/23/2007 9:49:33 PM
How to declare variable to define it as a column?

declare @Column AS (what should be here?)

AS

SELECT * FROM Users
WHERE @Column like....

Hrcko

Re: column Klas Klättermus
4/23/2007 10:09:11 PM
DECLARE @column nvarchar(32);
DECLARE @sqlstmt nvarchar(256);

EXEC sp_executesql @stmt=N'SELECT * FROM Users WHERE ' + @column + ' LIKE
....';

However avoid sp_executesql if you can. Even temporary tables are a better
solution.
http://msdn2.microsoft.com/en-us/library/aa933299(SQL.80).aspx


"Hrvoje" <hrvoje.voda2@zg.htnet.hr> skrev i meddelandet
news:f0j2k7$g5$1@ss408.t-com.hr...
[quoted text, click to view]

Re: column Hrvoje
4/24/2007 12:22:03 AM
I don't get anything with this code.
I just want to convert nvarchar(wich represent column name) to column name
in my WHERE statement.

[quoted text, click to view]

Re: column Tibor Karaszi
4/24/2007 6:27:49 PM
[quoted text, click to view]

.... and in order to do that you need to use dynamic SQL. See
http://www.sommarskog.se/dynamic_sql.html.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi


[quoted text, click to view]
AddThis Social Bookmark Button