Forum Replies Created

Viewing 15 posts - 61 through 75 (of 275 total)

  • RE: Count Function

    Also, keep in mind that you can do this:

    SELECT

    ...

    ,SUM (CASE WHEN CALL_TYPE_CD = 'UM' THEN 1 ELSE 0 END) AS CALL_TYPE_UM_CT

    ,SUM (CASE WHEN CALL_TYPE_CD = 'MA' THEN 1 ELSE...

  • RE: Optimization strategy?!

    You would be much off if you could create a reasonable, relevant clustered index. As Craig noted, SQL can be quirky when it comes to nonclus index usage.

    A clus...

  • RE: concatenating CASE stmt results

    Hmm, interesting. I guess so.

    But I don't see how could it be evaluated only once.

    I mean, how could SQL determine equality vs 5 (10, 20, 50, whatever)...

  • RE: concatenating CASE stmt results

    I don't see how that's a disadvantage of the simple CASE. The complex CASE will have the same issue for the same reason. The first version is still...

  • RE: Repeatative data

    I don't see the problem either, unless you just need to output all the original rows. If so, you can add an outer query that joins to a sequential...

  • RE: find table altered/created

    Your code is always referencing the current db. You need to use dynamic SQL to allow a db name to be added to the code:

    declare @sql varchar(4000)

    open dbnameCursor

    Fetch next...

  • RE: Substring error datetime from charater string

    If there will always be a date somewhere in the data, or if you only want to process rows that have a valid date embedded in them, you can do...

  • RE: Declaring a Variable using SUM()

    Or, if you really want to use SET:

    SET @currentBillAt = (SELECT SUM(bill_at) FROM chg_item where batch_id = 9785 )

  • RE: Declaring a Variable using SUM()

    SELECT @currentBillAt = SUM(bill_at) FROM chg_item where batch_id = 9785

  • RE: pass table name as a parameter in stored procedure

    To be safe, you should add brackets around the table name in bitbucket's code.

    Also, I strongly suggest using an alias on the table name instead of repeating the full table...

  • RE: increment string in vchar column

    Do both CTEs in the same statement with the UPDATE; you can have more than one CTE in a statement. That way it will all implicitly be in the...

  • RE: SQL-Server 2005: Change Ordinal Column Position

    I'd be nervous about meeting this request for a specific order of columns in a table, just because of the large number of tables in any significant db. That...

  • RE: Need to compare two columns

    Hopefully the code below will let you "invalid date" errors. You can't really guarantee that SQL will perform the checks in the order you want, but hopefully it will...

  • RE: increment string in vchar column

    You should split the alpha and numeric for storage. Don't fall into the trap of feeling you have to store what is displayed / entered.

    So, create two physical columns,...

  • RE: ORDER BY with CASE statement

    Something like this:

    ORDER BY

    CASE

    WHEN @SortSeq = 'asc' AND @SortOrder = 1 THEN machineName

    ...

Viewing 15 posts - 61 through 75 (of 275 total)