0

In a Sybase database I am working with result sets are used (misused?) as variables.

For example, one often finds lines such as the following:

select SOMETHING = 'bla' 

"SOMETHING" is technically a result set ... and the content of the result set is used by the application accessing the database. Since "SOMETHING" is not a variable, it does not get declared anywhere.

I have never seen this kind of hack before (and colleagues of mine couldn't explain to me the reason why it was done that way) and I have not found anything about it on google.

Is there some reference available that explains why one would want to use such a hack as opposed to "normal" variables?

Thomas_SO
  • 1,883
  • 2
  • 10
  • 20
  • How is the code normally invoked? Perhaps the calling program is looking for this particular result in the output; granted, there are different ways to send output back to the client but it also depends on how the client processes the output, eg, only capable of processing result sets, capable of processing 'print' output, etc. I routinely have scripts generate output for formatting/viewing/parsing purposes (though for this particular example I'd probably use a 'print' statement). I'd check the process that normally runs this code to see if it's expecting 'SOMETHING = bla' in the output. – markp-fuso Nov 27 '18 at 13:44

1 Answers1

0

I think you are not reading this correctly. This query simply means that there is a one-column result set with the column named 'SOMETHING'. This query is equivalent to: SELECT 'bla' AS SOMETHING

RobV
  • 2,263
  • 1
  • 11
  • 7
  • ok, so it's a 1-column result set with exactly one row, which contains the value 'bla' .... but what's the point? How can I use result set 'SOMETHING' now? Why not just declare a variable called "@something" and assign it the value 'bla' ? – Thomas_SO Nov 29 '18 at 16:32
  • Indeed there does not seem to be an immediate practical application, but this seems to be an example of a very simple SELECT query. So I guess the question is what this example was trying to illustrate. I don't know that. – RobV Dec 01 '18 at 11:59