Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Multiple Selects - How To?
Message
 
 
À
24/12/2009 14:13:47
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2005
Application:
Desktop
Divers
Thread ID:
01440575
Message ID:
01440582
Vues:
44
Even in VFP9 you don't need intermediate cursor. You can use derived table instead.
select CASE WHEN foo.ctype = 'REG' THEN foo.nregular_rate * foo.nHours ELSE foo.nOvertime_Rate * foo.nHours END as nTotal from
	(
		select jcprod.cjobno, 
		       jcprod.ctype,
		       jcprod.nhours,
		       CASE WHEN JCRate.nregular_rate0 THEN JCRate.nregular_rate ELSE DefaultRates.nregular_rate END as nRegular_Rate,
		       CASE WHEN JCRate.novertime_rate0 THEN JCRate.novertime_rate ELSE DefaultRates.novertime_rate END as nOvertime_Rate
		into cursor foo
		from dbo.JCProd
		Left JOIN dbo.DefaultRates DefaultRates ON jcprod.crate_type = DefaultRates.ctype_of_time
		Left JOIN dbo.JCRate JCRate ON jcprod.crate_type = JCRate.ctype_of_time and jcprod.cJobNo = JCRate.cJobNo
		where jcprod.cid = '56c1c878-e9d5-484a-a458-e98e3247a765'
	) dt1
>What's the best way for me to perform multiple select statements? I have come up with the following which works, However I really don't want to create a table called "foo" every time the script is run. In VPF I would have selected into a cursor and then based my second select on the cursor. How do I do this with MS SQL 2005?
>
>
>
>select jcprod.cjobno, 
>       jcprod.ctype,
>       jcprod.nhours,
>       CASE WHEN JCRate.nregular_rate>0 THEN JCRate.nregular_rate ELSE DefaultRates.nregular_rate END as nRegular_Rate,
>       CASE WHEN JCRate.novertime_rate>0 THEN JCRate.novertime_rate ELSE DefaultRates.novertime_rate END as nOvertime_Rate
>into cursor foo
>from dbo.JCProd
>Left JOIN dbo.DefaultRates DefaultRates ON jcprod.crate_type = DefaultRates.ctype_of_time
>Left JOIN dbo.JCRate JCRate ON jcprod.crate_type = JCRate.ctype_of_time and jcprod.cJobNo = JCRate.cJobNo
>where jcprod.cid = '56c1c878-e9d5-484a-a458-e98e3247a765'
>
>select CASE WHEN foo.ctype = 'REG' THEN foo.nregular_rate * foo.nHours ELSE foo.nOvertime_Rate * foo.nHours END as nTotal from foo
>
>
>
>TIA
>Jeff
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform