Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variables in SQL statements

0 views
Skip to first unread message

Zachary Dezman

unread,
Jun 26, 2000, 3:00:00 AM6/26/00
to
Everyone,

I wish to create an SQL statement in the form:

SELECT tblgrades.SearchText
FROM tblGrades

where tblGrades is the table being queried and SearchText is a variable
whose value is supplied by the user. Is this the right syntax? I want
the user to be able to ask for a column of values from a database.
Thanks for any help you can supply.


Zach Dezman


BPMargolin

unread,
Jun 26, 2000, 3:00:00 AM6/26/00
to
Zach,

declare @columnName sysname
select @columnName = 'SearchText'

exec ('select ' + @columnName + ' from tblGrades')

---------------------------------------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc) which can be
cut and pasted into Query Analyzer is appreciated.

Zachary Dezman <zde...@mines.edu> wrote in message
news:39578F28...@mines.edu...

0 new messages