March 3, 2016 at 2:22 am
I am trying to finding date difference between today's date and given date in the table.Some rows has 1 date while others has 2 dates (take earlier date). I tried with dynamic variable and temp table but still not working
declare @t nvarchar(1000)
set @t = ' select a.Availability from [ScrappedData_Regina] a'
if(len(@t) < = 55 ) -- for single date case
begin
SELECT * INTO #result1
FROM
(
select distinct [Product Name],[SKU],DATEDIFF(day,cast(right([Availability],10) as date),cast(GETDATE() as date)) as [Delivery Date]
from [ScrappedData_Regina]
where [Availability] like '%none%' -- total 158 products
)
end
else -- for two date case
begin
SELECT * INTO #result2
FROM
(
declare @t date
set @t = '
select SUBSTRING(Availability, PATINDEX('% [0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]%', [Availability]), 11) as [Date Part] from [ScrappedData_Regina] '
-- extracts date part from a column
select distinct [Product Name],[SKU],DATEDIFF(day,cast(@t as date),cast(GETDATE() as date)) as [Delivery Date] from ScrappedData_Regina
) -- i want to pass the date part in this select statement
select *into result from ( select * from #result1 union select * from #result2 )
The first query will give result as
And I want the same result for second query too for two dates case.
Finally combine both the result in a table
March 3, 2016 at 3:18 am
Hello, can you provide design of table and data based on one of links in my signature?
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply