TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sai Reddy
NA
214
31.6k
Case with Date column
Nov 5 2018 1:13 AM
Hi, I need to generate the report daily with date wise, I have written it with a case statement, How to avoid case statement to minimize the query because I need to add complete dates of a month. Please help me to write it in dynamic way.
CREATE TABLE Survey
(
City VARCHAR(20),
Date Date,
SaleAmount INT
)
SELECT City,
Sum(case when CONVERT(VARCHAR(10),Date,126)='2018-11-05' THEN SaleAmount else 0 end) as '2018-11-05',
Sum(case when CONVERT(VARCHAR(10),Date,126)='2018-11-04' THEN SaleAmount else 0 end) as '2018-11-04',
Sum(case when CONVERT(VARCHAR(10),Date,126)='2018-11-03' THEN SaleAmount else 0 end) as '2018-11-03'
FROM Survey group by City
Reply
Answers (
7
)
how index works in sql ?.
How to read dbf file &import structure & data in sql server