Viewing 15 posts - 3,901 through 3,915 (of 3,956 total)
Rats! Eugene posted:
To get time as HH:MM:SS from seconds, you don't need to calculates hours, minutes and seconds, format and concatenate them separately. You can just use one of...
March 15, 2012 at 6:38 pm
Ah so then every account code will have a transaction in every period?
March 15, 2012 at 6:20 pm
Assuming you mean time as something like HH:MM:SS, this may work:
DECLARE @seconds INT
SELECT @seconds = 500
SELECT RIGHT('00'+CAST(@seconds/3600 AS VARCHAR), 2) + ':' +
RIGHT('00'+CAST(@seconds/60 AS VARCHAR), 2) + ':' +
RIGHT('00''00'+CAST(@seconds...
March 15, 2012 at 5:11 am
C'mon Gila, surely you can be more helpful than that!
DECLARE @fromdate DATETIME
,@todate DATETIME
,@workstart DATETIME
,@workend DATETIME
SELECT @workstart = '2012-03-01 07:00:00', @workend = '2012-03-01 14:00:00'
SELECT @fromdate = '2012-03-14 10:00:00', @todate = '2012-03-15...
March 15, 2012 at 4:54 am
Here's another solution:
;WITH PLYTD AS (
SELECT Account, Organization, Period, [Year]
,(SELECT SUM(Amount) FROM @acct a2
WHERE a1.Account = a2.Account and a1.Organization = a2.Organization and a1.[Year] = a2.[Year] and
a2.Period <= a1.Period
) As Amount
FROM...
March 15, 2012 at 12:28 am
I'm sure someone is going to ask you to post your DDL, so I'll do it for you.
DECLARE @acct TABLE
(Account INT, Organization CHAR(3), Period CHAR(2), [Year] CHAR(4), Amount MONEY)
INSERT INTO...
March 13, 2012 at 11:27 pm
Thanks Dwain. I will try your idea too... but for the need of the hour -- resolved it with while loop...
You're welcome. But read my mantra 🙂
March 13, 2012 at 6:17 pm
Here's an interesting set of articles from Erland Sommarskog's site:
Those are good articles. I believe that is where I got the idea for...
March 13, 2012 at 5:05 am
Gianluca's response is the correct one.
However if you can't or don't want to use a table variable as a parameter, there are two other choices where you would need to...
March 13, 2012 at 4:36 am
Indeed, my bad for only skimming through the thread!
Jeff's was a valid question.
March 12, 2012 at 2:40 am
I like being contrary so I have to ask, why are you using a calendar table?
DECLARE @YourDate DATETIME
SET @YourDate = '2012-01-12'
SELECT COALESCE(
CASE WHEN DATEPART(weekday,DATEADD(day,-1,DATEADD(month, DATEDIFF(month, 0, @YourDate), 0))) IN...
March 12, 2012 at 2:00 am
There is a way to get a better query plan:
INSERT INTO @Temp (ItemID, RegionID, Quantity)
SELECT 4003, 5 ,10
UNION ALL SELECT...
March 12, 2012 at 1:00 am
Normally I'm a big fan of using CTEs to improve readability but in this case, I think I'd just write it like this:
DECLARE @Temp TABLE
(
ItemID ...
March 12, 2012 at 12:44 am
Another option:
DECLARE @data TABLE (C1 INT, C2 CHAR(1), REF001 INT, REF002 INT
,REF003 INT, REF004 INT, REF005 INT, REF006 INT)
INSERT @data
VALUES (1, 'A', 1, 2, 3, 4,...
March 9, 2012 at 1:35 am
I was actually thinking that you may be able to do the UPDATE first and then DELETE using a similar structure to what I did and avoid the OUTPUT and...
March 8, 2012 at 9:13 pm
Viewing 15 posts - 3,901 through 3,915 (of 3,956 total)