Forum Replies Created

Viewing 15 posts - 106 through 120 (of 414 total)

  • RE: SQL Report Help...Thanks

    Try this:

    select isnull(dt.usr_name, dt.off_name), dt.waiting, dt.sold, dt.dropped

    from

    (

      select off_name, usr_name,

      cast(sum(case when status = 'waiting' then amount else 0 end) as varchar)as waiting,

      cast(sum(case when status = 'sold' then amount...

  • RE: Getting only the first related result (with complications)

    It's a complicated world...

    Try this:

     

    declare @IDs table(Id int)

    set rowcount 1

    -- execute the same SQL statement 3 times

    insert @IDs select id from Games

    where id...

  • RE: SQL Report Help...Thanks

    Is this what you are looking for?

     

    select off_name, usr_name,

    sum(case when status = 'waiting' then amount else 0 end),

    sum(case when status = 'sold' then amount else 0 end),

    sum(case when status =...

  • RE: Adding sum of rows for dynomic purpose...

    Is this what you are looking for?

    select col1 + col2 + col3 + col4 + col5 from table

    Otherwise, please give us a small example with data and the expected output...

  • RE: Getting only the first related result (with complications)

    Are games always related in groups? In your test data, games 1, 2 and 3 are a group of related games. Similarly for games 6 and 7.

  • RE: SET based operation

    Good to hear - and you are absolutely right, I forgot "order by SKU_ID" in the function...

  • RE: sql query help

    Very interesting - and surprising, at least to me...

    I have removed the rest of my comments now that Jeff has rewritten his post...

  • RE: SET based operation

    OK - how about this one then? It uses a function that creates a comma separated list of SKU_IDs for a given CASE_NBR. To work correctly, ',' should not be...

  • RE: SET based operation

    I have some code that produces the output you want. It turned out to be more complicated than I thought it would be at first. My code requires that the...

  • RE: Pure SQL - One line, two tables

    Then try the following trick (which uses a function):

    -- Test data

    create table TABLE1 (ID int, FIELD1 varchar(10), FIELD2 varchar(10))

    go

    create table TABLE2 (TABLE1_ID int, ID int)

    go

    create function listValues(@ID int)

    returns varchar(8000)

    as

    begin

     declare @str...

  • RE: Dynamically dividing up queries

    You could try the following:

    declare @foo table (source_id_key int);

    insert into @foo select 1

    insert into @foo select 2

    insert into @foo select 4

    insert into @foo select 6

    insert into @foo select 7

    insert into...

  • RE: Dynamically dividing up queries

    How about using the modulo operator?

    The first group would be "where id % 7 = 0". The next group "where id % 7 = 1" and so on up to "where...

  • RE: Pure SQL - One line, two tables

    If this is only to stop duplicates from being displayed, you might want to try the code below. Displaying a comma separated list is harder and performes worse... Let me know...

  • RE: sql query help

    Do you have precisely two occurencies of each Id in your data (like in your test example)? Then you could try the following:

    select Id, max(Name) + ',' + min(Name) from yourtable group...

  • RE: T-SQL Teaser

    Ray probably means that you should execute

    select customerID, SomeString from mytable

    and then put data on the desired form in your client program.

     

    I was wondering if you have an additional column...

Viewing 15 posts - 106 through 120 (of 414 total)