If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Virtual tables?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-23-11, 05:46
Musil David Musil David is offline
Registered User
 
Join Date: Sep 2006
Location: Czech Republic
Posts: 82
Virtual tables?

Why I cannot use this?

declare @ln_x int
select @ln_x = x.col from ( select max(id) as col from table ) x

Server Message: Number 141, Severity 15
Server 'U00025_D', Line 2:
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.

but this works...

select x.col from ( select max(id) as col from table ) x

This example is trivial but I would like to use these constructions in my stored procedures...

e.g.

select .... from ( select ... from table ... ) a , table b, ( select ... from table ) c
where a.id = b.id
and c.id = b.id
and ...

or should I avoid these constlructions and use somthing else? Temporary tables (but if I am in transactions?)...
Reply With Quote
  #2 (permalink)  
Old 03-25-11, 03:14
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
I am unable to recreate your problem
Code:
1> declare @ln_x int
2> select @ln_x = x.col from ( select max(id) as col from sysobjects ) x
3> select lnx=@ln_x
4> go
(1 row affected)
 lnx         
 ----------- 
  2144007638 

(1 row affected)
Reply With Quote
  #3 (permalink)  
Old 03-25-11, 05:23
Musil David Musil David is offline
Registered User
 
Join Date: Sep 2006
Location: Czech Republic
Posts: 82
> declare @ln_x int
> select @ln_x = x.col from ( select max(id) as col from sysobjects ) x
> select lnx=@ln_x

Server Message: Number 141, Severity 15
Server 'U00025_D', Line 2:
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.


> select x.col from ( select max(id) as col from sysobjects ) x

col
-----------
2147460116



> select @@version

Adaptive Server Enterprise/12.5.3/EBF 13337 ESD#7/P/ia64/HP-UX B.11.23/ase1253/1951/64-bit/OPT/Fri Mar 24 00:47:27 2006
Reply With Quote
  #4 (permalink)  
Old 03-25-11, 11:37
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Successful on ASE 15.0.3 and 12.5.4
I don't have an older version to test on
Reply With Quote
  #5 (permalink)  
Old 03-28-11, 03:36
Martijnvs Martijnvs is offline
Registered User
 
Join Date: Jan 2004
Location: The Hague/Utrecht, NL
Posts: 415
Tested it on ASE12.5.0.3 and 12.5.3. The first gives an nicorrect syntaxt near select and ), the last gives Musil David's error.
__________________
I'm not crazy, I'm an aeroplane!
Reply With Quote
  #6 (permalink)  
Old 03-28-11, 04:19
Musil David Musil David is offline
Registered User
 
Join Date: Sep 2006
Location: Czech Republic
Posts: 82
Thanks... I ll upgrade version...

One more question what about effectivity of these kind of commands, are these more effective than

a ) division in more commands working with temporary tables...

b) division in more commands working with db tables...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On