Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SQL 2008 Query Help

Posted on 2010-11-25
5
Medium Priority
?
295 Views
Last Modified: 2012-05-10
Team,

I need to create a table which shows days of the week. Data is from Database.

i.e.,

Team        Sun        Mon         Tue     Wed        Thur        Fri      Sat

Headers are static.

Based on current date, (11/25/2010) which is a "Thurs" day, this data should come in Thurs field and all the before days should calculate automatically based on that respective date. Fri & Sat should be empty as no data will be there in the database.

If the current date is Sun, then rest of the data should be blank.

Pls guide me to write a query which will do this function.

Thanks,
David
0
Comment
Question by:davidi1
  • 2
  • 2
5 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34214193
Do you want to create a table or a query?
"this data should come in Thurs field"
Can you please explain what that means?  Data from some table that has a date column?
Does the query always show only 1 row (current week)?
Where does Team fit in?
0
 
LVL 2

Author Comment

by:davidi1
ID: 34214259
sorry. my bad. let me clarify more.

SQL Table Name: RawData

Fields:

TeamName, Date, Closecount

I already run a query to pullup dynamic table which will display last 7 days of data. however my org doesnt want that. they want to keep the headers static & want me to modify the query to satisfy the headers.

for every day ("Sun") ex:

5 rows will be generated as result.

I need to populate the same data with respect to days, Sun, Mon, Tue.., etc..,

lemme know if you have more questions.., sorry.., answering your question real fast as im jumping to a meeting. will be back to you in 15 mins.

Thanks,
David
0
 
LVL 61

Accepted Solution

by:
HainKurt earned 2000 total points
ID: 34214323
do you want something like this?


declare @aDate DateTime = getdate();
declare @dw int = datepart(dw, @aDate);

select @dw,
@aDate - @dw + 1 sun,
@aDate - @dw + 2 mon,
@aDate - @dw + 3 tue,
@aDate - @dw + 4 wed,
@aDate - @dw + 5 thu,
@aDate - @dw + 6 fri,
@aDate - @dw + 7 sat

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34214366
Sorry, but it is still not clear to me

for every day ("Sun") ex:
5 rows will be generated as result.

Why are there 5 rows for Sunday?
If you run it on a Thursday, I know you mentioned that Fri/Sat should be blank, but are the preceeding days also blank?
Do you want the closecount value from the table in the columns under the days, or the dates?
0
 
LVL 2

Author Comment

by:davidi1
ID: 34214478
Nevermind cyberkiwi.  Hainkurt resolved my problem.

Hainkurt: Bingo. This is exactly what i was looking for. Thanks. Its works great.

Thanks,
David
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question