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 STCan 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, butLTRIM(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 PostingDateCASE 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 Column1FROM dbo.StagingTable ST???Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
|
|
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 columnsounds 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 Column1FROM dbo.StagingTable STWHERE 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 MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|