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
 Formatting data in SQL
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dipesh.ccsu
Starting Member

USA
7 Posts

Posted - 03/28/2013 :  13:49:20  Show Profile  Reply with Quote
Hi All, i am new to SQL and need some help with formatting the data for certain columns. Please see below



CREATE VIEW FINANCE_USER_TBLS.ddc582_OCAM_FINAL AS(

SELECT A.Acct_Uniq_Cust_No,
A.ACT_MAX_DT,
B.Acct_Act_DT,
CASE WHEN A.ACT_MAX_DT= B.Acct_Act_DT THEN 'MAX' ELSE 'NOT' END UPLOAD_DATE

FROM FINANCE_USER_TBLS.ddc582_OCAM_MAX A, FINANCE_USER_TBLS.ddc582_OCAM_UPLOAD B

WHERE A.Acct_Uniq_Cust_No = B.Acct_Uniq_Cust_No

Above is my view table, where I am trying to retrieve data from two tables based on the case statement. Below is my output. The issue is the act max dt and acct act dt has the same info but are formatted different in terms of the dates. Any suggestion how can I change the data format to be the same for act max dt and acct act dt.


RESULT

Act Max Dt
2698571898013/03/22
2604326642013/03/08

Acct Act Dt
269857189802013-03-22
260432664202013-03-08


Upload Date
NOT
NOT




Edited by - dipesh.ccsu on 03/28/2013 13:57:50

James K
Flowing Fount of Yak Knowledge

3593 Posts

Posted - 03/28/2013 :  14:23:47  Show Profile  Reply with Quote
The columns ACT_MAX_DT and Acct_Act_DT are probably of character data types. In general, the best practice is to use DATETIME or another date/time data type when you want to store data/time. Assuming the columns are character data type, you can use replace to convert one to be like the other. For example, if you wanted ot use "/"
CREATE VIEW FINANCE_USER_TBLS.ddc582_OCAM_FINAL AS(

SELECT A.Acct_Uniq_Cust_No,
A.ACT_MAX_DT,
REPLACE(B.Acct_Act_DT,'-','/') as ,Acct_Act_DT
CASE WHEN A.ACT_MAX_DT= B.Acct_Act_DT THEN 'MAX' ELSE 'NOT' END UPLOAD_DATE

FROM FINANCE_USER_TBLS.ddc582_OCAM_MAX A, FINANCE_USER_TBLS.ddc582_OCAM_UPLOAD B

WHERE A.Acct_Uniq_Cust_No = B.Acct_Uniq_Cust_No )
Go to Top of Page

jeffw8713
Aged Yak Warrior

USA
794 Posts

Posted - 03/28/2013 :  14:26:20  Show Profile  Reply with Quote
You can use replace to remove the / or -.

CASE WHEN replace(a.act_max_dt, '/', '') = replace(b.acct_act_dt, '-', '') THEN 'MAX' ELSE 'NOT'
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.06 seconds. Powered By: Snitz Forums 2000