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 >>