JackTimber (8/28/2014)
Naa re, its a different asignment. I am working by keeping ChrisM solution as a base from previous example, and lets see.If i come up with a solution would definitely post the result . 🙂
ok..I am not really sure where you are with understanding the previous thread solutions and what you have posted as a "new" question in this thread.
for what it is worth...and with no relevance to your previous post, and based entirely on the sample data you have posted in this thread....here is a possible solution that provides what you have requested...whether this delivers effectively ...only you can tell...and then tell us if you need more help.
WITH CTE_SORT as (
SELECT
UserName
, Drink
, Value
, CreatedDate
, ROW_NUMBER() OVER (ORDER BY createddate) AS rn
FROM #TEMP)
,
CTE_HD as (
SELECT
rn - 1 AS sn
FROM cte_sort
WHERE (Drink = 'harddrink'))
SELECT
cs.UserName
, cs.Drink
, cs.Value
FROM cte_sort cs INNER JOIN
cte_hd ch ON cs.rn = ch.sn;
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day