Greetings,
Very simple question, how do i assign a column same name as its value?
declare @.seas varchar(5) set @.seas = 'Donie'
SELECT @.seas as (')
NOT static please, dynamic. So, SELECT @.seas as 'Donie' won't do me any
good.
Much obliged,
Don
*** Sent via Developersdex http://www.examnotes.net ***don larry wrote:
> Greetings,
> Very simple question, how do i assign a column same name as its value?
> declare @.seas varchar(5) set @.seas = 'Donie'
> SELECT @.seas as (')
> NOT static please, dynamic. So, SELECT @.seas as 'Donie' won't do me
> any good.
> Much obliged,
> Don
>
>
> *** Sent via Developersdex http://www.examnotes.net ***
You need to use dynamic sql, which has security implications if you are
using stored procedures.
For example:
declare @.seas varchar(5)
declare @.sql nvarchar(1000)
set @.seas = 'Donie'
set @.sql = N'SELECT [' + @.seas + N'] from dbo.mytable'
Exec sp_executesql @.sql
David Gugick
Imceda Software
www.imceda.com|||The first obvious question would be "Why would you want to do this?"
Assuming there was some reason, you have to use dynamic SQL to get this kind
of
dynamic feature.
Declare @.Sql VarChar(8000)
Declare @.Seas VarChar(5)
Set @.Sql= 'Select ' + QuoteName(@.Seas, '''') + ' As ' + QuoteName(@.Seas)
Exec(@.Sql)
Thomas
"don larry" <donlarry17@.hotmail.com> wrote in message
news:%23mwQMTAXFHA.2776@.TK2MSFTNGP12.phx.gbl...
> Greetings,
> Very simple question, how do i assign a column same name as its value?
> declare @.seas varchar(5) set @.seas = 'Donie'
> SELECT @.seas as (')
> NOT static please, dynamic. So, SELECT @.seas as 'Donie' won't do me any
> good.
> Much obliged,
> Don
>
>
> *** Sent via Developersdex http://www.examnotes.net ***|||>> how do i assign a column same name as its value? <<
Okay, you missed the whole idea of data modeling, RDBMS, and just about
everything else for the past 35 years in the field. Not a minor
misunderstanding, but all of it at the foundation level. Entities,
attributes and values are TOTALLY DIFFERENT! This is like being in a
math newsgroup and having someone ask "Can I make 2+2=5 If I have
really large values of 2?"
Really bad SQL programmers can use proprietary, dynamic code to kludge
things like this. But if you actually want to be competent, get a good
book on RDBMS and data model, read it and stop programming until you
understand what you are doing.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment