MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 26th, 2012, 08:15 AM
citi citi is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 1 citi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 41 sec
Reputation Power: 0
Need help for start sql

hi,
i am new in sql and i need your help,
i m trying to find the age from year of brith and peoles who have more then 25 years old
so i have a tabel

T1
id.p name year
----------------------------------
1 jack 1975
2 rocky 1999
3 robaun 1945
4 cyral 1992

so i try

SELECT year FROM T1 WHERE YEAR > 25


but this isn't work, how can i do?
thanks for help

Reply With Quote
  #2  
Old October 26th, 2012, 09:16 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,349 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 7 h 20 m 59 sec
Reputation Power: 390
Code:
select <columnsOfInterest>
  from t1
 where year(getdate()) - year > 25

Reply With Quote
  #3  
Old October 26th, 2012, 11:49 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,369 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 19 m 34 sec
Reputation Power: 4140
alternatively...
Code:
WHERE t1.year < YEAR(GETDATE()) - 25
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #4  
Old October 26th, 2012, 12:22 PM
gk53 gk53 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 28 m 25 sec
Reputation Power: 8
Quote:
DATEDIFF(YEAR, '1/1/' + cast(ryear as CHAR(4)), GETDATE()) > 25

will work too

Reply With Quote
  #5  
Old October 26th, 2012, 01:28 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,369 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 19 m 34 sec
Reputation Power: 4140
but which of these approaches will allow the query to be optimized to use an index, and which will force a table scan?

there's more to writing a query than just getting the right answer

Reply With Quote
  #6  
Old October 26th, 2012, 02:33 PM
gk53 gk53 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 71 gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level)gk53 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 8 h 28 m 25 sec
Reputation Power: 8
Actually, execution plan will be the same in all 3 variants...

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Need help for start sql

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap