Forum Replies Created

Viewing 15 posts - 91 through 105 (of 414 total)

  • RE: Conditional Summing

    How about the following:

    select sum(case when price >= 20 then price*1.15 when price >= 10 then price*1.1 else price end) from Orders

     

  • RE: How To !! - Master Detail Query returning flat result set

    Make sure you have proper indexes on the tables involved. I suggest you equip the #Master table with a unique clustered index on ID and the #DetailTable with a unique clustered...

  • RE: left right node hierarchy

    Could you post a small example of a parent/child hierachy together with the output you are looking for?

     

  • RE: assitance with aggregates

    Try this left join:

    select a.question, c.answer, count(b.answer)

    from questions a

    cross join

    (select 'Y' as answer union select 'N' union select 'U')

    c

    left join answers b on a.qid = b.qid and c.answer = b.answer

    group...

  • RE: T-SQL #TempTable headace

    You could also try the following, which doesn't use a temp table:

    Select Field1, Field2, Field3 from Table

    order by

    case when [Condition1] then Field3 else null end,

    case when [Condition1] then Field2 else null...

  • RE: Pass a rowset to a nested stored procedure?

    It is probably better to create a permanent table like the following:

    testtable(SPID int, RecordId int)

    Then, when you insert data into it, do as follows:

    delete testtable where SPID = @@SPID

    insert testtable...

  • RE: Pass a rowset to a nested stored procedure?

    You could access the temptable inside your stored procedure. Or you could pass the record-ID's to the stored procedure in a comma separated string.

    If this doesn't help, please give us...

  • RE: How To !! - Master Detail Query returning flat result set

    Alternatively (using KH's table definitions):

    select m.ID, m.Field1, m.Field2, d1.Field1 as Detail_R1_F1, d2.Field1 as Detail_R2_F1, d3.Field1 as Detail_R3_F1

    from #MasterTable m

    left join #DetailTable d1

    on m.ID = d1.ID and d1.Record = 1

    left join...

  • RE: Change a X orientd results set to X oriented.

    You don't have to do that much typing... In your favourite programming language, write a loop with 87 (or 150) iterations to produce the query you are after. Then copy...

  • RE: weekly report

    Nice solution, Vasc...   But you might want to use

    WHERE DATEDIFF(wk,@StartDay,[date]) + 1 <= Col1

    instead, otherwise the first data returned will be from the...

  • RE: Case and Dates

    You didn't write what the problem was But I guess your query fails. Try this instead:

    SELECT UserEmail, UserDisplayName, CASE

     WHEN DATEADD(mi, -10, GETDATE()) <...

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

    I realised that there may be a problem with David B's second suggestion. Consider the example below. David B's suggestion returns 1, 4, 5. If my interpretation is correct I...

  • RE: Running totals and first match

    Is this what you are looking for?

     

    declare @newtable table(InvNum int, InvCrtDt datetime, InvPstDt datetime, Balance int, RunningBalance int, ZeroDte bit null, Days int null)

    insert @newtable

    select b.InvNum, b.InvCrtDt, b.InvPstDt, b.Balance, sum(c.Balance),...

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

    Very nice and certainly better than my suggestion

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

    I think we read the following differently:

    The related table tells which games are related to which, but how do I get the select statement to realize that it should not...

Viewing 15 posts - 91 through 105 (of 414 total)