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.

Cast in ASE

4 posts in General Discussion Last posting was on 2012-05-15 08:53:27.0Z
RobertW Posted on 2012-05-10 14:42:58.0Z
From: RobertW <rkratsch@hotmail.com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120420 Thunderbird/12.0
MIME-Version: 1.0
Newsgroups: sybase.public.ase.general
Subject: Cast in ASE
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4fabd3f2@forums-1-dub>
Date: 10 May 2012 07:42:58 -0700
X-Trace: forums-1-dub 1336660978 10.22.241.152 (10 May 2012 07:42:58 -0700)
X-Original-Trace: 10 May 2012 07:42:58 -0700, vip152.sybase.com
Lines: 20
X-Authenticated-User: techsupp
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:31102
Article PK: 73993

Hi

Executing convert with a nullability change works fine:

create table test (c1 int not null,c2 varchar(20) null)
select convert (numeric(5,0) null, c1) as c1,c2 into netab from test
--OK

In cast I allways get an syntax error:

select cast (c1 as numeric(5,0) null) as c1,c2 into netab from test
--Incorrect syntax near the keyword 'null'.
--Severity Level=15, State=2, Transaction State=1

The documentation said that the nullability change is in both variants
possible.

Thanks

Robert


Rob V Posted on 2012-05-10 16:56:37.0Z
From: Rob V <rob@sypron.nl>
Reply-To: rob@sypron.nl
User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
MIME-Version: 1.0
Newsgroups: sybase.public.ase.general
Subject: Re: Cast in ASE
References: <4fabd3f2@forums-1-dub>
In-Reply-To: <4fabd3f2@forums-1-dub>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4fabf345@forums-1-dub>
Date: 10 May 2012 09:56:37 -0700
X-Trace: forums-1-dub 1336668997 10.22.241.152 (10 May 2012 09:56:37 -0700)
X-Original-Trace: 10 May 2012 09:56:37 -0700, vip152.sybase.com
Lines: 54
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:31103
Article PK: 73992


On 10-May-2012 16:42, RobertW wrote:
> Hi
>
> Executing convert with a nullability change works fine:
>
> create table test (c1 int not null,c2 varchar(20) null)
> select convert (numeric(5,0) null, c1) as c1,c2 into netab from test
> --OK
>
> In cast I allways get an syntax error:
>
> select cast (c1 as numeric(5,0) null) as c1,c2 into netab from test
> --Incorrect syntax near the keyword 'null'.
> --Severity Level=15, State=2, Transaction State=1
>
> The documentation said that the nullability change is in both variants
> possible.
>
> Thanks
>
> Robert

That looks like an error in the documentation (and this has probably
always been there); I'll get it corrected.
Reason why I think this is that the ANSI standard does not seem to allow
specifying the nullability this way.

Note that you can create nullable result expressions by specifying NULL
as the value being casted, e.g.


select a=cast (null as varchar(10)), b = cast (0 as varchar(10))
into tempdb..tt

...creates one nullable column and one that is not nullable.


HTH,

Rob V.
-----------------------------------------------------------------
Rob Verschoor

Certified Professional DBA for Sybase ASE, IQ, Replication Server

Author of Sybase books (order online at www.sypron.nl/shop):
"Tips, Tricks & Recipes for Sybase ASE"
"The Complete Sybase IQ Quick Reference Guide" (new!)
"The Complete Sybase ASE Quick Reference Guide"
"The Complete Sybase Replication Server Quick Reference Guide"

rob@NO.SPAM.sypron.nl | www.sypron.nl | Twitter: @rob_verschoor
Sypron B.V., The Netherlands | Chamber of Commerce 27138666
-----------------------------------------------------------------


Michael Peppler [Team Sybase] Posted on 2012-05-11 04:43:07.0Z
From: "Michael Peppler [Team Sybase]" <mpeppler@peppler.org>
Organization: Peppler Consulting SARL
Subject: Re: Cast in ASE
User-Agent: Pan/0.14.2 (This is not a psychotic episode. It's a cleansing moment of clarity.)
Message-ID: <pan.2012.05.11.04.44.14.241715@peppler.org>
Newsgroups: sybase.public.ase.general
References: <4fabd3f2@forums-1-dub> <4fabf345@forums-1-dub>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Date: 10 May 2012 21:43:07 -0700
X-Trace: forums-1-dub 1336711387 10.22.241.152 (10 May 2012 21:43:07 -0700)
X-Original-Trace: 10 May 2012 21:43:07 -0700, vip152.sybase.com
Lines: 34
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:31105
Article PK: 73995


On Thu, 10 May 2012 09:56:37 -0700, Rob V wrote:

> On 10-May-2012 16:42, RobertW wrote:
>> Hi
>>
>> Executing convert with a nullability change works fine:
>>
>> create table test (c1 int not null,c2 varchar(20) null) select convert
>> (numeric(5,0) null, c1) as c1,c2 into netab from test --OK
>>
>> In cast I allways get an syntax error:
>>
>> select cast (c1 as numeric(5,0) null) as c1,c2 into netab from test
>> --Incorrect syntax near the keyword 'null'. --Severity Level=15,
>> State=2, Transaction State=1
>>
>> The documentation said that the nullability change is in both variants
>> possible.
>>
>> Thanks
>>
>> Robert
>
> That looks like an error in the documentation (and this has probably
> always been there); I'll get it corrected. Reason why I think this is that
> the ANSI standard does not seem to allow specifying the nullability this
> way.

However - you can specify nullability with convert():

select convert(varchar(20) null, foo) from bar ...

Michael


Robert Kratschmann Posted on 2012-05-15 08:53:27.0Z
From: Robert Kratschmann <rkratsch@sybase.com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1
MIME-Version: 1.0
Newsgroups: sybase.public.ase.general
Subject: Re: Cast in ASE
References: <4fabd3f2@forums-1-dub> <4fabf345@forums-1-dub>
In-Reply-To: <4fabf345@forums-1-dub>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: vip152.sybase.com
X-Original-NNTP-Posting-Host: vip152.sybase.com
Message-ID: <4fb21987$1@forums-1-dub>
Date: 15 May 2012 01:53:27 -0700
X-Trace: forums-1-dub 1337072007 10.22.241.152 (15 May 2012 01:53:27 -0700)
X-Original-Trace: 15 May 2012 01:53:27 -0700, vip152.sybase.com
Lines: 62
X-Authenticated-User: techsupp
Path: forums-1-dub!not-for-mail
Xref: forums-1-dub sybase.public.ase.general:31107
Article PK: 73997

Hi Rob,

many thanks for the info

Robert

Am 10.05.2012 18:56, schrieb Rob V:

> On 10-May-2012 16:42, RobertW wrote:
>> Hi
>>
>> Executing convert with a nullability change works fine:
>>
>> create table test (c1 int not null,c2 varchar(20) null)
>> select convert (numeric(5,0) null, c1) as c1,c2 into netab from test
>> --OK
>>
>> In cast I allways get an syntax error:
>>
>> select cast (c1 as numeric(5,0) null) as c1,c2 into netab from test
>> --Incorrect syntax near the keyword 'null'.
>> --Severity Level=15, State=2, Transaction State=1
>>
>> The documentation said that the nullability change is in both variants
>> possible.
>>
>> Thanks
>>
>> Robert
>
> That looks like an error in the documentation (and this has probably
> always been there); I'll get it corrected.
> Reason why I think this is that the ANSI standard does not seem to allow
> specifying the nullability this way.
>
> Note that you can create nullable result expressions by specifying NULL
> as the value being casted, e.g.
>
>
> select a=cast (null as varchar(10)), b = cast (0 as varchar(10))
> into tempdb..tt
>
> ...creates one nullable column and one that is not nullable.
>
>
> HTH,
>
> Rob V.
> -----------------------------------------------------------------
> Rob Verschoor
>
> Certified Professional DBA for Sybase ASE, IQ, Replication Server
>
> Author of Sybase books (order online at www.sypron.nl/shop):
> "Tips, Tricks & Recipes for Sybase ASE"
> "The Complete Sybase IQ Quick Reference Guide" (new!)
> "The Complete Sybase ASE Quick Reference Guide"
> "The Complete Sybase Replication Server Quick Reference Guide"
>
> rob@NO.SPAM.sypron.nl | www.sypron.nl | Twitter: @rob_verschoor
> Sypron B.V., The Netherlands | Chamber of Commerce 27138666
> -----------------------------------------------------------------