Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Temp Tbl - Behavioural issues

Author  Topic 

Indsqlbeginner
Starting Member

21 Posts

Posted - 2014-08-06 : 01:32:51
Dear Team

i'm facing some behavioural issues with the temp tbl in sql 2012 version.

qry details are below

select distinct txtMonth + ' - '+ txtFiscalYear as txtMonthValue,intMonth,intYear,MAX(intTimePKID) as intTimePKID into #temp

from tblcaldender

where dtDate > DATEADD(mm,-12,getdate()) and dtDate <= GETDATE()

group by txtMonth + ' - '+ txtFiscalYear,intMonth,intYear

order by intTimePKID desc

select txtMonthValue as txtLabel,txtMonthValue as txtValue from #temp

drop table #temp



in 2012 version o/ p as below. its coming up in alphabetical order where as in 2008 version it's coming up correctly as per PKID.could you please help.

April - FY15
August - FY14
August - FY15
December - FY14
February - FY14
January - FY14
July - FY15
June - FY15
March - FY14
May - FY15
November - FY14
October - FY14
September - FY14

sz1
Aged Yak Warrior

555 Posts

Posted - 2014-08-06 : 08:48:08
Try this:

select txtMonthValue as txtLabel,txtMonthValue as txtValue from #temp
order by DATEPART(mm,CAST([txtMONTHValue]+ ' 1900' AS DATETIME)) asc

We are the creators of our own reality!
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-08-06 : 15:28:38
If you do a select without an ORDER BY clause there is no guarantee which order the data will be returned. So, as SZ1, showed, you need to add an ORDER BY clause to your select statement. You didn't show what your data is so you may just be able to order by the column or you may need to convert it as SZ1 showed.
Go to Top of Page
   

- Advertisement -