[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Need a change to sql query

Posted on 2012-08-16
6
Medium Priority
?
260 Views
Last Modified: 2012-08-23
Hello,
I need to change the date and time in the below sql query to the following:

the second date to be the today's date (2012-08-13 00:00:00 to show today's date)
the first date to be the todays date - 8 days (2012-08-05 00:00:00 to show the todays date minus 8 days)

XLODBC
1
DSN=nw_src;Description=live;UID=sa;APP=2007 Microsoft Office system;WSID=ITOFF03
SELECT maghroom.building_code, maghmaster.short_title, maghmaster.first_name, maghmaster.last_name, maghmaster.address_1, maghmaster.address_2, maghmaster.city_code, maghmaster.state_province_code, maghmaster.zip_postal_code, maghmaster.work_phone_number, maghmaster.home_phone_number, maghmaster.email_address, maghroom.reservation_number, maghroom.room_code, maghvisit.reservation_status, maghvisit.arrival_date, maghvisit.departure_date, maghvisit.room_revenue_total, maghvisit.other_revenue_total, maghmaster.total_amount_spent  FROM nw_src.dbo.maghmaster maghmaster, nw_src.dbo.maghroom maghroom, nw_src.dbo.maghvisit maghvisit  WHERE maghmaster.guest_client_code = maghroom.guest_client_code AND maghmaster.guest_client_code = maghvisit.guest_client_code AND maghroom.building_code = maghvisit.building_code AND maghroom.reservation_number = maghvisit.reservation_number AND maghroom.guest_client_code = maghvisit.guest_client_code AND ((maghroom.building_code='nbb') AND (maghvisit.reservation_status='3') AND (maghvisit.departure_date>{ts '2012-08-05 00:00:00'} And maghvisit.departure_date<{ts '2012-08-13 00:00:00'}))  ORDER BY maghroom.building_code


building_code      short_title      first_name      last_name      address_1      address_2      city_code      state_province_code      zip_postal_code      work_phone_number      home_phone_number      email_address      reservation_number      room_code      reservation_status      arrival_date      departure_date      room_revenue_total      other_revenue_total      total_amount_spent


Thank you,
Plamen
0
Comment
Question by:plamski
  • 3
  • 3
6 Comments
 
LVL 14

Assisted Solution

by:Farzad Akbarnejad
Farzad Akbarnejad earned 1000 total points
ID: 38303641
Hi,
Change the table of your query to:

...  AND (maghvisit.departure_date> DATEADD( "d",-8, getdate() ) And maghvisit.departure_date<getdate() )) ...

-FA
0
 

Author Comment

by:plamski
ID: 38306298
It takes the code but gives me error:

Category      Timestamp      Message
Statusbar      8/17/2012 3:40:46 PM      SQL Server Database Error: Conversion failed when converting datetime from character string.


I think it is doing that becuase there is date and time in the <maghvisit.departure_date> table
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 38307225
Hi,

Try to convert field to datetime data type:


...  AND (  CONVERT(datetime, maghvisit.departure_date) > DATEADD( "d",-8, getdate() ) And CONVERT(datetime, maghvisit.departure_date) < getdate() )) ...

-FA
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Accepted Solution

by:
plamski earned 0 total points
ID: 38308083
It worked when I changet to the following:

maghvisit.departure_date BETWEEN getdate()-8 and getdate()

I still get the conversion error but it doesn't matter because it pulls the correct dates.

Plamen
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 38308101
Glad to assist you  :)
-FA
0
 

Author Closing Comment

by:plamski
ID: 38324048
I used the FarzadA's solution and I modified it a bit to get to the one i came up with.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

873 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