all groups > sql server programming > january 2004 >
You're in the

sql server programming

group:

query not possible???


query not possible??? antonio catalano
1/4/2004 11:35:49 PM
sql server programming:
After declared a variable launch the query
"select (@dec_var=@dec_var + 1 ) as mia , t.* from
nome_table t"
The query not run.
How come ???
Re: query not possible??? anonymous NO[at]SPAM discussions.microsoft.com
1/5/2004 12:27:29 AM

[quoted text, click to view]
"select (if@dec_var=@dec_var + 1 ) as mia , t.* from
nome_table t"
The query not run.
How come ???
Thanks
..
in mysql run
mysql_query('set @attivita:=0');
mysql_query('set @incremento:=0');
mysql_query('select giorno ,matricola,if(fid_attivita!
=@attivita,@attivita:=fid_attivita,@attivita) as
attivita ,min(cinquina) as da ,max(cinquina) as a from
pres group by matricola,if
(fid_attivita=@attivita,@incremento,@incremento:=@increment
o+1) ,attivita having attivita!=45 ;');
Re: query not possible??? David Portas
1/5/2004 7:52:49 AM
You can't assign a variable in a SELECT statement that also returns a result
set.

This should work:

SELECT @dec_var = @dec_var + 1

SELECT @dec_var AS mia , t.*
FROM nome_table t

If that's not what you want then please explain in more detail what you are
trying to achieve.

--
David Portas
------------
Please reply only to the newsgroup
--

Re: query not possible??? David Portas
1/5/2004 9:11:25 AM
I'm not familiar with MySQL so I'm not certain what this code does but as
far as I can tell it should be possible to implement it in standard SQL.

CASE can be used in place of the Immediate IF() function.

Various methods can be used to output an incrementing row count. For example
(using Pubs):

SELECT COUNT(*) row_count, A.au_id, A.au_lname, A.au_fname
FROM Authors AS A
JOIN Authors AS B
ON A.au_id >= B.au_id
GROUP BY A.au_id, A.au_lname, A.au_fname


But there may be better solutions depending on your requirements. (Do you
actually want the count in your result set? If not then you maybe don't need
anything like the above).

If you need more help, please post the DDL (CREATE TABLE statement) for your
table(s), including keys and constraints. Also post some sample data as
INSERT statements and show your required result based on that sample data.

--
David Portas
------------
Please reply only to the newsgroup
--

AddThis Social Bookmark Button