Viewing 15 posts - 211 through 225 (of 1,438 total)
There's an unpleasant XML conversion that may work for you
WITH source AS (
SELECT Deptid,Dept_name,location,HASHBYTES('MD5',CAST(Deptid AS VARCHAR(10)) + Dept_name + location) AS col
FROM department)
SELECT Deptid,Dept_name,location,
...
February 17, 2015 at 5:33 am
Try this
SELECT *
FROM #Machine m
WHERE m.MachineTypeFk = 99
AND m.OnHand = 0
AND m.Enabled = 0
AND EXISTS(SELECT * FROM #MachineBranch mb WHERE mb.MachineFk = m.MachinePk)
...
February 12, 2015 at 9:22 am
Here's another version, this one using SQL Server 2012 LEAD
WITH Source AS (
SELECT *
FROM
(VALUES
(1, 'A',convert(datetime,'20150101'),convert(datetime,'20150331')),
(2, 'B','20150115','20150215'),
(3, 'C','20150215','20150315'),
(4, 'D','20150115','20150315'),
(5, 'E','20150401','20150415')
) AS TimeIntervals(OrderId, status, DateStart, DateEnd)
),
Starts AS (
SELECT...
February 11, 2015 at 9:32 am
The problem is due to two intervals having a one day gap between the end of one and the start of the next, I think these can simply be excluded.
Change
CROSS...
February 11, 2015 at 6:33 am
It was getting the wrong values for ordereid and status in some circumstances.
February 11, 2015 at 4:53 am
tomek tomek (2/11/2015)
First of all, thank you all for your input. It is invaluable.
a) you solutions with numbers looks very interesting, but as Dwain suggested I had problems...
February 11, 2015 at 3:42 am
This works with your data, not very efficient though
WITH Source AS (
SELECT *
FROM
(VALUES
(1, 'A',convert(datetime,'20150101'),convert(datetime,'20150331')),
(2, 'B','20150115','20150215'),
(3, 'C','20150215','20150315'),
(4, 'D','20150115','20150315'),
(5, 'E','20150401','20150415')
) AS TimeIntervals(OrderId, status, DateStart, DateEnd)
),
Starts AS (
SELECT a.DateStart...
February 10, 2015 at 4:11 pm
You can nest CASE expressions
,CASE WHEN com.completion_date IS NOT NULL AND dim.DayName <> 'Saturday'
THEN CASE WHEN DATEDIFF(d, com.current_task_target_date,com.completion_date) < non1.NoWorkDays THEN 0 ELSE DATEDIFF(d, com.current_task_target_date,com.completion_date) - non1.NoWorkDays END
WHEN com.completion_date...
February 6, 2015 at 4:30 am
Use a CASE expression
CASE WHEN MyColumn < 0 THEN 0 ELSE MyColumn END
February 6, 2015 at 4:21 am
a20213 (2/5/2015)
why you consider it odd ? i was reading a text on anti - pattern representations, that's from where i took the "idea" of this representation.
Because there's a lot...
February 5, 2015 at 2:47 am
Seems an odd representation of a hierarchy but this gives you the correct results
WITH CTE AS (
SELECT la.label AS ancestor,
...
February 5, 2015 at 2:35 am
Have you tried running my last query?
February 3, 2015 at 11:43 am
This is a bit of a guess...
select t1.id,
stuff((select ','+x.r.value('./text()[1]','nvarchar(max)') as "text()"
from tblxmldata t2
cross apply t2.xmltext.nodes('/associatedText/value') as...
February 3, 2015 at 8:12 am
Try this
select stuff(
(select ','+x.r.value('./text()[1]','nvarchar(max)') as "text()"
from tblxmldata
cross apply xmltext.nodes('/associatedText/value') as x(r)
for xml path('')),1,1,'')
February 3, 2015 at 7:55 am
Assuming xmltext is of type XML
select x.r.value('./text()[1]','nvarchar(max)') as AssociatedText
from tblxmldata
cross apply xmltext.nodes('/associatedText/value') as x(r)
February 3, 2015 at 7:36 am
Viewing 15 posts - 211 through 225 (of 1,438 total)