Viewing 15 posts - 2,806 through 2,820 (of 3,957 total)
ChrisM@Work (9/13/2012)
SELECT
Id, A, B, C,
MinVal
FROM #MinAmt
CROSS APPLY (
SELECT MIN(a)
FROM (VALUES (A),(B),(C) ) v (a)
WHERE a > 0
) x (MinVal)
😉
And the referee throws down a...
September 13, 2012 at 4:55 am
ChrisM@Work (9/13/2012)
dwain.c (9/12/2012)
...BTW Chris - Thanks for the credit!
No worries mate - so long as you keep up the repayments! 😛
The check is in the mail!
I'm wondering how improvements #1...
September 13, 2012 at 4:51 am
Eugene - Actually, I'm not sure which version of your code I tested against, possibly an earlier one. That one was running in about 16ms as I recall, where...
September 13, 2012 at 4:49 am
Here's a version of the Tuples solution that runs in about 1/3 the time:
;WITH SourceNums AS (
SELECT strcol FROM (VALUES ('1'),('2'),('5'),('7'),('8'),('9')) a (strcol)
),
nTuples (n, Tuples) AS (
...
September 12, 2012 at 11:48 pm
ChrisM@Work (9/12/2012)
;WITH SourceNums AS (
SELECT strcol FROM (VALUES ('1'),('2'),('5'),('7'),('8'),('9')) a (strcol)
),
nTuples (n, Tuples) AS (
SELECT 1, CAST(strcol...
September 12, 2012 at 11:22 pm
This is pretty short too but subject to the DATEFORMAT setting (I think):
SELECT DAY_, MONTH_, YEAR_
,CAST(RTRIM(MONTH_) + '-' + RTRIM(DAY_) + '-' + RTRIM(YEAR_) AS...
September 12, 2012 at 11:11 pm
texpic (9/12/2012)
If all three are zero, desired result would be zero.
What if all 3 are negative? Still zero?
September 12, 2012 at 9:54 pm
Ah yes, NULLIF... Forgot about that one.
That will work but we still need to hear from the OP their preferred return result for that case so it can be plugged...
September 12, 2012 at 9:24 pm
Michael Valentine Jones (9/12/2012)
dwain.c (9/12/2012)
;WITH MyValues AS (
SELECT Id
,A=CASE WHEN A > 0 THEN A ELSE...
September 12, 2012 at 8:57 pm
Another way:
;WITH MyValues AS (
SELECT Id
,A=CASE WHEN A > 0 THEN A ELSE 2147483647 END
...
September 12, 2012 at 7:11 pm
Another way:
-- To get just the table names
SELECT DISTINCT TABLE_NAME
FROM information_schema.view_column_usage
WHERE VIEW_NAME = 'v_YourView'
-- To get table and column names
SELECT TABLE_NAME, COLUMN_NAME
FROM information_schema.view_column_usage
WHERE VIEW_NAME = 'v_YourView'
September 12, 2012 at 6:53 pm
Assuming you're using a TIME field to store your values, you can use a Tally table and the built-in DATEADD/DATEDIFF functions for this:
DECLARE @t TABLE
(OfficeId INT,...
September 12, 2012 at 6:42 pm
Jeff Moden (9/12/2012)
dianne.howard (9/12/2012)
We have a list of customer transactions that are grouped together...
September 12, 2012 at 6:25 pm
bpowers (9/12/2012)
September 12, 2012 at 6:22 pm
My archaeological dig uncovered the following:
SELECT a.name
,LTRIM(RIGHT(defn, LEN(defn) - (3 + CHARINDEX(' as ', defn))))
FROM sys.all_objects a
INNER JOIN sys.sql_modules b
ON a.object_id =...
September 12, 2012 at 3:40 am
Viewing 15 posts - 2,806 through 2,820 (of 3,957 total)