Forum Moderators: open

Message Too Old, No Replies

ms Sql

Automatically plugging in ids from 1

         

malcolmcroucher

11:11 am on Feb 20, 2009 (gmt 0)

10+ Year Member



Hi ,

I need to create a temporary table in ms sql and then create a field iID which has values which are automatically inserted .

Here is the temp table and the insert into the temp table :

ECLARE @tPast TABLE

(

xiID INT
,RegionID INT
,xRegion VARCHAR(100)
,xSalesoffice VARCHAR(100)
,xPlannedV INT
,xActualV INT
,xMon VARCHAR(100)
,xYears INT

)

---SET IDENTITY_INSERT @tPast OFF

INSERT INTO @tPast
SELECT ST.iID ,STT.iRegion, R.cName ,STT.iSalesOffice , ST.fPlannedValue , ST.fActualValue , Pe.cname ,PE2.cname FROM

Salestargettype STT

INNER JOIN Salestarget ST ON STT.iID =ST.isalestargettype
INNER JOIN Region R ON R.iId = STT.iRegion
INNER JOIN Period PE WITH(NOLOCK) ON PE.iID = ST.iPeriod
INNER JOIN Period PE2 WITH(NOLOCK) ON PE2.iID = PE.iParent

WHERE
--STT.iSalestargetcategory = @Sales

PE.iParent IS NOT NULL
AND R.cname = @cRegion
AND DATEADD(day, - 365 ,@newstart) <= PE.dstart
AND DATEADD(day, - 365 ,@newend ) >= PE.dEnd

GROUP BY
PE2.Cname , PE.cname ,ST.iID , STT.iregion,R.cname,STT.isalesoffice,ST.fplannedvalue,ST.factualvalue ---, PE.dstart , Pe.dend

Order BY
PE2.cname

Regards

Malcolm