Sybase NNTP forums - End Of Life (EOL)

The NNTP forums from Sybase - forums.sybase.com - are now closed.

All new questions should be directed to the appropriate forum at the SAP Community Network (SCN).

Individual products have links to the respective forums on SCN, or you can go to SCN and search for your product in the search box (upper right corner) to find your specific developer center.

how to variable column names

10 posts in Product Futures Discussion Last posting was on 2002-02-06 16:52:29.0Z
Niel_Junea Posted on 2002-02-01 16:55:55.0Z
From: Niel_Junea
Date: Fri, 1 Feb 2002 11:55:55 -0500
Newsgroups: sybase.public.ase.product_futures_discussion
Subject: how to variable column names
Message-ID: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums>
Lines: 13
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:823
Article PK: 94355

Can anyone tell how to specify a column name in an update query which is
stored in a local variable.
What I want to do is:

update #MyTable
set @RatingColumn = 200



In the above query @RatingColumn is a local variable which stores the
column determined on the fly from a result from a cursor.

Thanks in advance.


PhilipL Posted on 2002-02-06 16:52:29.0Z
From: PhilipL
Date: Wed, 6 Feb 2002 11:52:29 -0500
Newsgroups: sybase.public.ase.product_futures_discussion
Subject: Re: how to variable column names
Message-ID: <8D6F49D2D2F4CA2F005CB24985256B58.00606A2985256B53@webforums>
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums>
Lines: 7
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:798
Article PK: 94325

You might be able to also use a workaround with the case statement, i.e.

Case
when situation a is true then update vara
when situation b is true then update varb
when situation c is true then update varc
end


Bret Halford Posted on 2002-02-01 17:04:52.0Z
Message-ID: <3C5ACAB4.2A2F6036@sybase.com>
Date: Fri, 01 Feb 2002 10:04:52 -0700
From: Bret Halford <bret@sybase.com>
Organization: Sybase, Inc.
X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Subject: Re: how to variable column names
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.ase.product_futures_discussion
Lines: 15
NNTP-Posting-Host: 130.214.8.37
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:822
Article PK: 94350

You can use the existing EXECUTE IMMEDIATE functionality:


declare @cmdstring varchar(255)
select @cmdstring = "update #MyTable set "+@RatingColumn+" = 200"
execute (@cmdstring)

-bret

Niel_Junea wrote:

> Can anyone tell how to specify a column name in an update query which is
> stored in a local variable.
> What I want to do is:
>
> update #MyTable
> set @RatingColumn = 200
>
> In the above query @RatingColumn is a local variable which stores the
> column determined on the fly from a result from a cursor.
>
> Thanks in advance.


Niel_Juneja Posted on 2002-02-01 18:54:20.0Z
From: Niel_Juneja
Date: Fri, 1 Feb 2002 13:54:20 -0500
Newsgroups: sybase.public.ase.product_futures_discussion
Subject: Re: how to variable column names
Message-ID: <782786B343CC00AB0067D9EF85256B53.006340CD85256B53@webforums>
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums> <3C5ACAB4.2A2F6036@sybase.com>
Lines: 10
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:820
Article PK: 94347

thanks very much Bret. Looks very neat. But when I compile the stored
procedure, I get an error saying
"incorrect syntax near ( on line 661"

and line 661 is -> execute (@cmdstring)

do I have to do anything special to use the execute facility ?
like set execute_immediate on or smthg like that

Niel.


Bret Halford Posted on 2002-02-01 18:45:12.0Z
Message-ID: <3C5AE237.4C1E59FC@sybase.com>
Date: Fri, 01 Feb 2002 11:45:12 -0700
From: Bret Halford <bret@sybase.com>
Organization: Sybase, Inc.
X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Subject: Re: how to variable column names
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums> <3C5ACAB4.2A2F6036@sybase.com> <782786B343CC00AB0067D9EF85256B53.006340CD85256B53@webforums>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.ase.product_futures_discussion
Lines: 13
NNTP-Posting-Host: 157.133.80.180
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:819
Article PK: 94348

What version are you on? EXECUTE IMMEDIATE is available from ASE 12.0
on,
but not in earlier versons. No special configuration is needed.

-bret

Niel_Juneja wrote:

> thanks very much Bret. Looks very neat. But when I compile the stored
> procedure, I get an error saying
> "incorrect syntax near ( on line 661"
>
> and line 661 is -> execute (@cmdstring)
>
> do I have to do anything special to use the execute facility ?
> like set execute_immediate on or smthg like that
>
> Niel.


Niel_Juneja Posted on 2002-02-01 19:28:57.0Z
From: Niel_Juneja
Date: Fri, 1 Feb 2002 14:28:57 -0500
Newsgroups: sybase.public.ase.product_futures_discussion
Subject: Re: how to variable column names
Message-ID: <AAF36ACBFA95D971006B056585256B53.006AD69B85256B53@webforums>
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums> <3C5ACAB4.2A2F6036@sybase.com> <782786B343CC00AB0067D9EF85256B53.006340CD85256B53@webforums> <3C5AE237.4C1E59FC@sybase.com>
Lines: 1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:817
Article PK: 94344


Niel_Juneja Posted on 2002-02-01 19:28:57.0Z
From: Niel_Juneja
Date: Fri, 1 Feb 2002 14:28:57 -0500
Newsgroups: sybase.public.ase.product_futures_discussion
Subject: Re: how to variable column names
Message-ID: <185E702E3EC59B14006B053B85256B53.006AD69B85256B53@webforums>
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums> <3C5ACAB4.2A2F6036@sybase.com> <782786B343CC00AB0067D9EF85256B53.006340CD85256B53@webforums> <3C5AE237.4C1E59FC@sybase.com>
Lines: 1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:818
Article PK: 94345


Niel_Juneja Posted on 2002-02-01 19:30:16.0Z
From: Niel_Juneja
Date: Fri, 1 Feb 2002 14:30:16 -0500
Newsgroups: sybase.public.ase.product_futures_discussion
Subject: Re: how to variable column names
Message-ID: <CEF1E4AD155560B3006B242A85256B53.006AD69B85256B53@webforums>
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums> <3C5ACAB4.2A2F6036@sybase.com> <782786B343CC00AB0067D9EF85256B53.006340CD85256B53@webforums> <3C5AE237.4C1E59FC@sybase.com>
Lines: 6
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com!webforums.sybase.com!news
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:816
Article PK: 94346

I m on 11.9 or smthg like that. Definetly some 11.

so is there asny way, I can achieve the same in ASE versions less than 12.

Thanks,
Niel.


Bret Halford Posted on 2002-02-01 19:42:38.0Z
Message-ID: <3C5AEFAE.BD032F3B@sybase.com>
Date: Fri, 01 Feb 2002 12:42:38 -0700
From: Bret Halford <bret@sybase.com>
Organization: Sybase, Inc.
X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Subject: Re: how to variable column names
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums> <3C5ACAB4.2A2F6036@sybase.com> <782786B343CC00AB0067D9EF85256B53.006340CD85256B53@webforums> <3C5AE237.4C1E59FC@sybase.com> <CEF1E4AD155560B3006B242A85256B53.006AD69B85256B53@webforums>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.ase.product_futures_discussion
Lines: 9
NNTP-Posting-Host: 157.133.80.180
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:814
Article PK: 94341

There is an open feature request for the ability to use variables in place of
object
and column names, the CR number is 28974.

-bret

Niel_Juneja wrote:

> I m on 11.9 or smthg like that. Definetly some 11.
>
> so is there asny way, I can achieve the same in ASE versions less than 12.
>
> Thanks,
> Niel.


Bret Halford Posted on 2002-02-01 19:39:56.0Z
Message-ID: <3C5AEF0B.512F848A@sybase.com>
Date: Fri, 01 Feb 2002 12:39:56 -0700
From: Bret Halford <bret@sybase.com>
Organization: Sybase, Inc.
X-Mailer: Mozilla 4.76 [en] (Windows NT 5.0; U)
X-Accept-Language: en
MIME-Version: 1.0
Subject: Re: how to variable column names
References: <A2E5DE22872AEC4A005D02AB85256B53.005D02E185256B53@webforums> <3C5ACAB4.2A2F6036@sybase.com> <782786B343CC00AB0067D9EF85256B53.006340CD85256B53@webforums> <3C5AE237.4C1E59FC@sybase.com> <CEF1E4AD155560B3006B242A85256B53.006AD69B85256B53@webforums>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Newsgroups: sybase.public.ase.product_futures_discussion
Lines: 12
NNTP-Posting-Host: 157.133.80.180
Path: forums-1-dub!forums-master.sybase.com!forums.sybase.com
Xref: forums-1-dub sybase.public.ase.product_futures_discussion:815
Article PK: 94342

Not that I know of. You might check the dynamic sql links at
http://www.sypron.nl/download.html,
they have an excellent discussion of what is possible in the various versions.

But you really should look at upgrading - 11.9.2 is being end-of-lifed on
3/31/2002

-bret

Niel_Juneja wrote:

> I m on 11.9 or smthg like that. Definetly some 11.
>
> so is there asny way, I can achieve the same in ASE versions less than 12.
>
> Thanks,
> Niel.