SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Format Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 12/09/2013 :  03:46:07  Show Profile  Reply with Quote
Hi All

I spent all weekend trying to resolve this, but to no avail
Aim – Count How many FDMSAccountNo, with the account status 1 &16, when the [LAST-STATUS-CHG] was previous month.

My query so far is
SELECT 'Closing balance of previous month',
count(FDMSAccountNo)
FROM [FDMS].[dbo].[stg_LMPAB501]
where [ACCOUNT-STATUS] in ('01','16')

[LAST-STATUS-CHG]
Column Name [LAST-STATUS-CHG]
DataType :nvarchar(6)
The data is represented like this “020312”

Would appreciate any help available, as this is really bugging me

webfred
Flowing Fount of Yak Knowledge

Germany
8768 Posts

Posted - 12/09/2013 :  04:08:32  Show Profile  Visit webfred's Homepage  Reply with Quote
"020312" is it YYMMDD or MMDDYY or DDMMYY or what is it?


Too old to Rock'n'Roll too young to die.
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 12/09/2013 :  04:26:09  Show Profile  Reply with Quote
HI webfred
Dateformat is mmddyy
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8768 Posts

Posted - 12/09/2013 :  04:44:06  Show Profile  Visit webfred's Homepage  Reply with Quote
where [ACCOUNT-STATUS] in ('01','16')
and left([LAST-STATUS-CHG],2) = month(dateadd(month,-1,getdate()))


Too old to Rock'n'Roll too young to die.
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 12/09/2013 :  05:38:41  Show Profile  Reply with Quote
HI Webfred

i lied its actually DDMMYY
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8768 Posts

Posted - 12/09/2013 :  05:44:57  Show Profile  Visit webfred's Homepage  Reply with Quote
where [ACCOUNT-STATUS] in ('01','16')
and substring([LAST-STATUS-CHG],3,2) = month(dateadd(month,-1,getdate()))



Too old to Rock'n'Roll too young to die.
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 12/09/2013 :  05:52:48  Show Profile  Reply with Quote
Hi Webfred

i have done the following " right([LAST-STATUS-CHG],2) as year" to isolate the year

if i want to get the current year would it be right([LAST-STATUS-CHG],2) =year(GETDATE())
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 12/09/2013 :  06:13:19  Show Profile  Reply with Quote
quote:
Originally posted by masond

Hi Webfred

i have done the following " right([LAST-STATUS-CHG],2) as year" to isolate the year

if i want to get the current year would it be right([LAST-STATUS-CHG],2) =year(GETDATE())


ideally it should be
[code]
...
CASE WHEN right([LAST-STATUS-CHG],2) >= 50 THEN '19' ELSE '20' END + right([LAST-STATUS-CHG],2) =year(GETDATE())
..
[/code


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000