Viewing 9 posts - 1 through 9 (of 9 total)
Hope this is what you are looking for:
SELECT code, transdate,SumTransLast7days = ISNULL(c.sumoftran, 0) FROM #Test a
CROSS APPLY
(SELECT sumoftran = SUM(nooftran) FROM #Test b
WHERE b.Code = a.code
AND (b.transdate > DATEADD(dd,-7,a.TransDate) and...
February 24, 2013 at 9:25 pm
Below is a basic example for Group By
CREATE TABLE #Studentcourseschedule(
Department int,
Courseid int,
studentid int)
go
insert into #Studentcourseschedule(Department, Courseid,studentid)
values(1,1,1)
,(1,2,1)
,(1,3,1)
,(1,1,5)
,(1,3,6)
,(1,1,7)
,(2,2,1)
,(2,1,2)
,(2,3,2)
go
select department, COUNT(studentid) Studentcount
from #Studentcourseschedule
group by department
order by Department
go
select department, courseid, COUNT(studentid) Studentcount
from #Studentcourseschedule
group by...
February 24, 2013 at 9:11 pm
What is the problem you are facing when you create the UDF?
February 24, 2013 at 8:24 pm
Hi Craig,
Thank you for the explanation. I understood (The dt* are alias name for the derived queries and the q* and n are the alias name for the columns)...
February 5, 2013 at 9:25 pm
Hi Lynn,
Just to understand, Could you please explain how the query works? Especially the part
(SELECT 1) dt1(n)
CROSS APPLY (SELECT COUNT(*) FROM dbo.Customers) dt2(q1)
...
February 5, 2013 at 5:00 pm
Hi,
From what I understand from your query is that you want to compare the C.dCreated field for currentdate and fetch data. Hope below should solve the problem.
Begin
--declare @d_today datetime
--set @d_today=(select...
February 4, 2013 at 5:03 pm
Is this what you are expecting?
SELECT a.customer, a.status, DATEDIFF(dd, a.mlastupdt, getdate()) AS NumDays
FROM (SELECT Customer, max(LastUpdateDate) AS mlastupdt, [Status], createddate
...
February 3, 2013 at 8:55 pm
begin
declare @COLOR VARCHAR(20);
set @COLOR = NULL
select id,ISNULL(color,'NULL') color from TBLCOLOR where color in
(select color from TBLCOLOR where color = COALESCE(@COLOR,color))
or isnull(color, 0) = isnull(@COLOR,0)
end
OUTPUT:
idcolor
1RED
2BLUE
3NULL
4GREEN
5BLACK
6NULL
January 30, 2013 at 12:25 am
Is this what you are looking for?
---Set paramter to NULL
begin
declare @COLOR VARCHAR(20);
set @COLOR = NULL
select id,color from TBLCOLOR where color in
(select color from TBLCOLOR where color = COALESCE(@COLOR,color))
or...
January 29, 2013 at 11:47 pm
Viewing 9 posts - 1 through 9 (of 9 total)