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 2008 Forums
 Transact-SQL (2008)
 CASE STATEMENT assistance

Author  Topic 

MikeMiller
Starting Member

7 Posts

Posted - 2012-03-28 : 14:09:17
Hello!

I have a bit of a problem and hoping someone can assist. I'm still somewhat green to TSQL and need to import/parse data from a flat file into a table but only get the last two days from today’s date based on my PostingDate column.

LTRIM(RTRIM(Substring(Staging_Run, 93,1))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 94,10))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 104,8))) AS PostingDate
CASE WHEN PostingDate < DATEADD(DAY, -2, GETDATE())END AS PostingDate,
LTRIM(RTRIM(Substring(Staging_Run, 112,8))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 120,13)))AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 133,5))) AS Column1
FROM dbo.StagingTable ST

Can someone point in the right direction on how to go about this? I pretty sure it's in a CASE STATEMENT but I'm stuck on what to do next.

Any input is appreciated!

THANKS!

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-28 : 14:39:39
Not sure what you are doing, but

LTRIM(RTRIM(Substring(Staging_Run, 93,1))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 94,10))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 104,8))) AS PostingDate
CASE WHEN LTRIM(RTRIM(Substring(Staging_Run, 104,8))) < DATEADD(DAY, -2, GETDATE())END AS PostingDate,
LTRIM(RTRIM(Substring(Staging_Run, 112,8))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 120,13)))AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 133,5))) AS Column1
FROM dbo.StagingTable ST


???


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-28 : 15:00:41
need to import/parse data from a flat file into a table but only get the last two days from today’s date based on my PostingDate column

sounds like a filter requirement for me

...
LTRIM(RTRIM(Substring(Staging_Run, 93,1))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 94,10))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 104,8))) AS PostingDate,
LTRIM(RTRIM(Substring(Staging_Run, 112,8))) AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 120,13)))AS Column1,
LTRIM(RTRIM(Substring(Staging_Run, 133,5))) AS Column1
FROM dbo.StagingTable ST
WHERE CONVERT(datetime,LTRIM(RTRIM(Substring(Staging_Run, 104,8)))) >= DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()) -2, 0)
AND CONVERT(datetime,LTRIM(RTRIM(Substring(Staging_Run, 104,8)))) < DATEADD(DAY,DATEDIFF(DAY,0,GETDATE()), 0)

...


i hope Staging_Run has date values in proper unambiguos format YYYYMMDD

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -