Forum Replies Created

Viewing 15 posts - 181 through 195 (of 920 total)

  • RE: SQL Query: Subtract data from consecutive rows uptil non zero value reached.

    Assuming that the last rownumber for any currentline is the one to be subtracted:

    select a.[CurrentLine], a.amount, b.amount, (a.amount - b.amount) as 'total'

    from [AmountTable] a join AmountTable b on a.CurrentLine =...


    And then again, I might be wrong ...
    David Webb

  • RE: Concatenating two derived columns gives error,looking for a work around ?

    This is the third thread you've started on this same issue. People, including me, have given you solutions on some threads when you have already been given as good...


    And then again, I might be wrong ...
    David Webb

  • RE: Convert HHMMSS to HH:MM:SS

    Not very elegant, but... :

    declare @timec decimal(6,0)

    set @timec = 7

    select case when datalength(convert(varchar(6),@timec)) = 1

    ...


    And then again, I might be wrong ...
    David Webb

  • RE: substring/charindex

    Once you create the function, it's really not that hard...

    declare @dept varchar(200)

    set @dept = 'A,B,C'

    select item from [DelimitedSplit8K](@dept,',')

    item

    A

    B

    C

    The article is by Jeff Moden (who had probably forgotten more about this...


    And then again, I might be wrong ...
    David Webb

  • RE: Query Help

    OK, I'd do it slightly differently. Here's a link to the famous 8k splitter.

    http://www.sqlservercentral.com/articles/Tally+Table/72993/

    And I'd probably use it like:

    drop table #x1

    create table #x1

    (ano int,

    dept varchar(30))

    insert into #x1 values(1,'A1,A3,A5,A7')

    insert into...


    And then again, I might be wrong ...
    David Webb

  • RE: substring/charindex

    And a link to my favorite string splitter. Don't leave home without it...

    http://www.sqlservercentral.com/articles/Tally+Table/72993/


    And then again, I might be wrong ...
    David Webb

  • RE: Query Help

    OK,

    select ano from #x1 where dept like '%a1%' or dept like '%a5%' or dept like '%a6%'

    order by ano

    would do it, but I suspect there is more...

    Will these 3 conditions be...


    And then again, I might be wrong ...
    David Webb

  • RE: Query Help

    Tempting to just say:

    select ano from #x1 where ano <> 4

    order by ano

    but there must be some rule involving the 'dept' column in play here. What is the...


    And then again, I might be wrong ...
    David Webb

  • RE: Some way to write an INNER JOIN, but joining on either of two columns

    It's not clear what you're trying to accomplish. Some sample data and sample expected results would help to clear that up. If the mainzip and alternatezip both match...


    And then again, I might be wrong ...
    David Webb

  • RE: TTYL

    I had a boss once who said that English had no real spelling rules and therefore couldn't really be called a language. He pointed out that 'GHOTI' could be...


    And then again, I might be wrong ...
    David Webb

  • RE: Need to help to Restore/attach a database in SQL 6.5

    Were these files copied from a SQL Server that was running when the files were copied? If so, they may not be in a state that will allow them...


    And then again, I might be wrong ...
    David Webb

  • RE: Urgent Query Help

    OK, this code:

    UPDATE T1 SET [September 2012 Billing File] = CASE WHEN T2.[Application ID] IS NOT NULL AND T2.[ServerName]

    IS NOT NULL AND [TB Billed This Month] <> 0 THEN...


    And then again, I might be wrong ...
    David Webb

  • RE: Urgent Query Help

    This one says if the tested column is NOT = 0, then it will update with a 'y'. Your post isn't really clear about what the actual results of...


    And then again, I might be wrong ...
    David Webb

  • RE: Format 235959 as a time w/ AM/PM

    What version of SQL Server are you running? You posted this in the SQL Server 2008 forum, so I assumed you were on that version or better.


    And then again, I might be wrong ...
    David Webb

  • RE: Format 235959 as a time w/ AM/PM

    Lowell's is better, just need to add the varchar convert:

    select

    [active_end_time],

    convert(varchar(20),CONVERT(time,STUFF(STUFF(convert(varchar,[active_end_time]),3,0,':'),6,0,':')),100) as val

    from [msdb].[dbo].[sysschedules]


    And then again, I might be wrong ...
    David Webb

Viewing 15 posts - 181 through 195 (of 920 total)