Viewing 15 posts - 1,246 through 1,260 (of 3,957 total)
Of course, if you can guarantee the maximum number of sub-rows that there are (my assumption below is 2, controlling the number of LAGs to COALESCE), you may be able...
October 27, 2013 at 7:13 pm
Luis Cazares (10/25/2013)
LAG value can go any rows back. That's the second parameter of the function. Check example C on the LAG documentation.
Unfortunately the LAG function goes back a fixed...
October 27, 2013 at 7:06 pm
Remarks from BOL:
If the number of rows in a partition is not divisible by integer_expression, this will cause groups of two sizes that differ by one member. Larger groups come...
October 27, 2013 at 6:47 pm
Hmmm... I was really hoping to hear back from the OP whether my suggestion helped.
October 27, 2013 at 6:36 pm
Jeff Moden (10/25/2013)
Hey Alex,Throw your test data into some readily consumable code and I'll be happy to show you how to do this.
I'll be a little more charitable...
October 27, 2013 at 6:33 pm
Revenant (10/25/2013)
Luis Cazares (10/25/2013)
October 27, 2013 at 6:10 pm
David Burrows (10/25/2013)
Clearly we are having way too much fun here! 😛
October 25, 2013 at 6:27 pm
A bit of a different take on this, just for fun.
WITH SampleData (ID, MyString) AS
(
SELECT 1, '1:1,3,5,7,4:56,43,58,5:34,67r,234'
)
SELECT ID
,ItemNumber
,value1=CASE...
October 25, 2013 at 4:14 am
Post retracted... not enough coffee this morning.
October 24, 2013 at 6:30 pm
Yet another way:
SELECT *
FROM iPhones a
CROSS APPLY
(
SELECT TOP 1 location_id, date_assigned
FROM location_history b
WHERE a.iphone_id = b.iphone_id
...
October 24, 2013 at 6:24 pm
With a multi-line TVF like you have there, as Grant points out you need to define the table columns.
If you can convert it into an inline TVF (and the sample...
October 23, 2013 at 10:13 pm
This WHILE LOOP might be a little cleaner and faster than what you've got and should resolve to any number of levels.
DECLARE @increment TINYINT
DECLARE @didinsert TINYINT
/* create test data for...
October 23, 2013 at 9:20 pm
I guess its going to depend on how many levels you need but I believe this works on your test data:
WITH AllPersons AS
(
SELECT DISTINCT c.partykey
...
October 23, 2013 at 8:54 pm
Pulivarthi Sasidhar (10/22/2013)
Use the following Function....
CREATE FUNCTION fn_getrowsfrmCSVstring(@str varchar(max))
returns @rtn table (id int identity(1,1),value varchar(2000))
As
Begin
Declare
@mstr varchar(max),@i INT,@len INT
SELECT...
October 22, 2013 at 4:02 am
You probably want to do something like this then:
WITH SampleData AS
(
SELECT userid, [date], usage
FROM
(
...
October 21, 2013 at 11:00 pm
Viewing 15 posts - 1,246 through 1,260 (of 3,957 total)