Solved

Clueless about the right syntax. (GETDATE)

Posted on 2011-03-17
2
246 Views
Last Modified: 2012-05-11
Question: I would like to use GETDATE() in combination with IF THEN.

SELECT datepart(mm,getdate()) WHEN 1 print ''yada yada yada" ELSE print "yoda yoda yoda"

Since I'm a noob with SQL I can't seem to get the notation right.
I have searched myself silly on the web for the answer but with no luck.
Could someone tell me what the correct notation should be?

Thanks in advance!

Best regards,
Clyde.
0
Comment
Question by:Clyde_Radcliffe
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35155955
check out this:

SELECT CASE datepart(mm,getdate()) WHEN 1 THEN 'yada yada yada' ELSE 'yoda yoda yoda' END

Open in new window


resp:

declare @res varchar(100) 
SELECT CASE datepart(mm,getdate()) WHEN 1 THEN 'yada yada yada' ELSE 'yoda yoda yoda' END
print @res

Open in new window

0
 

Author Comment

by:Clyde_Radcliffe
ID: 35155990
@angelllll: Excellent! Thanks for the help!!!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
table fragmentation 40 74
Problem with SqlConnection 5 117
SQL query 4 29
Script to randomly create characters in MS SQL 6 18
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now