Ive have a real issue in trying to make a decision in which way to go.
In essence the proc will bring back one row from multiple data sets over and over from the webserver. In terms of reads it could reach upto 10 reads p/second. So what I need a something that's rapid. The first table where the initial data is captured is 50 mill rows and is clustered. ( SQL 2012 ent )
Calling the accountid and some information is quick however it is at that point where my conflict began in what to do next.
In calling the accountid and its information I wanted to use the customer id and call other information but not use the customer id within the first select.
Choice 1 double select
Declare @accountid varchar (10)
Select accountid, blah , blah , blah From table1 where accountid = @accountid
Select customerid FRom table1 where accountid = @accountid -- a fuction using this cusomterid would bring back more information.
---
Choice 2using a tmp table
Select accountid, blah , blah , blah , customerid into #tmp From table1 where accountid = @accountid
Select accountid, blah , blah , blah from #tmp
Select customerid from #tmp
-- choice 3 although is CTE ? but there is a limitation
WITH ACC_CTE (
accountid , blah, blah, blah , customerid )
AS
( Select accountid, blah , blah , blah , customerid From table1 where accountid = @accountid )
Select accountid , blah, blah, blah FROM acc_CTE
but you cant reuse the CTESelect customerid from acc_CTE therefore forcing u back to using
Select customerid FRom table1 where accountid = @accountid
From an execution plan options 1 and 3 are quicker and have the only two queries. I thought the CTE would have been the better choice but cant seen the benefit of it if you cant reselect it ??
Thanks