Viewing 15 posts - 61 through 75 (of 275 total)
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 24, 2010 at 4:03 pm
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 24, 2010 at 3:58 pm
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)...
Scott Pletcher, SQL Server MVP 2008-2010
September 21, 2010 at 10:24 am
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 21, 2010 at 10:03 am
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 21, 2010 at 9:55 am
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 20, 2010 at 3:14 pm
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 20, 2010 at 3:04 pm
Or, if you really want to use SET:
SET @currentBillAt = (SELECT SUM(bill_at) FROM chg_item where batch_id = 9785 )
Scott Pletcher, SQL Server MVP 2008-2010
September 17, 2010 at 10:11 am
SELECT @currentBillAt = SUM(bill_at) FROM chg_item where batch_id = 9785
Scott Pletcher, SQL Server MVP 2008-2010
September 17, 2010 at 10:10 am
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 15, 2010 at 2:18 pm
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 15, 2010 at 1:34 pm
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 14, 2010 at 9:42 am
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...
Scott Pletcher, SQL Server MVP 2008-2010
September 13, 2010 at 12:47 pm
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,...
Scott Pletcher, SQL Server MVP 2008-2010
September 13, 2010 at 12:34 pm
Something like this:
ORDER BY
CASE
WHEN @SortSeq = 'asc' AND @SortOrder = 1 THEN machineName
...
Scott Pletcher, SQL Server MVP 2008-2010
September 10, 2010 at 8:19 am
Viewing 15 posts - 61 through 75 (of 275 total)