SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 entering current date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ausla
Starting Member

7 Posts

Posted - 07/11/2012 :  23:47:35  Show Profile  Reply with Quote
Hi all,

I am new to this Sql Programming. IF i didn't asked correctly forgive me and please help help me .
I am pasting my code here and what i want to do is i want to get the current year and current semester and current tt_id from the sql server. But i don't know how to write a program. I was highlighted what i wrote but i want to make it generic instead of entering the date, semester and tt_id.
Can anybody help me please
My code is this
SELECT DISTINCT ttdays.day_code, ttmast.prd_code, subtab.sub_abrev, ttmast.room_code FROM studsub, subtab, teacher, ttdays, ttmast WHERE studsub.yr_study = ttmast.year_num AND ttmast.tt_id ='57' AND ttmast.class = studsub.class AND ((ttmast.year_num='2012'AND (ttmast.semester='3'

Grifter
Posting Yak Master

214 Posts

Posted - 07/12/2012 :  05:45:04  Show Profile  Reply with Quote
You mean you want to select all year, semester and tt_id results not just the ones you hard-coded for?

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22460 Posts

Posted - 07/12/2012 :  09:23:32  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Use variables for tt_id and semester and year(getdate()) for 2012. You can pass the values to the variables

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
261 Posts

Posted - 07/12/2012 :  09:30:32  Show Profile  Reply with Quote
I believe you are missing some join conditions between the 4 tables you are using in your select. if you are not properly joining tables, this will lead to a Cartesian product result which you dont need.

revise your table joins

--------------------------
Get rich or die trying
--------------------------
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 07/12/2012 :  09:33:46  Show Profile  Reply with Quote
do you've field in your table where uou store tt_id values?

for current year you could use YEAR(GETDATE())

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ausla
Starting Member

7 Posts

Posted - 07/12/2012 :  19:21:46  Show Profile  Reply with Quote
Hi, not all Year Just the current year,current semester and current tt_id those columns are in the respected tables. but for the year i got the reply like DatePart(year,GetDate()) but i dont know how to do the same way for semester and tt_id .
thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 07/12/2012 :  20:16:24  Show Profile  Reply with Quote
quote:
Originally posted by ausla

Hi, not all Year Just the current year,current semester and current tt_id those columns are in the respected tables. but for the year i got the reply like DatePart(year,GetDate()) but i dont know how to do the same way for semester and tt_id .
thank you


does table containing semester and tt_id have date field? or anything which relates it to dates?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ausla
Starting Member

7 Posts

Posted - 07/13/2012 :  00:53:01  Show Profile  Reply with Quote
does table containing semester and tt_id have date field? or anything which relates it to dates?

Semester containing single digit numbers like 1,2,3,4 and tt_id contains two digit numbers like 55,56,57..
thanks for your help

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/


[/quote]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47040 Posts

Posted - 07/13/2012 :  10:08:37  Show Profile  Reply with Quote
you didnt get my question. i'm not asking on data in columns semester and tt_id

i was asking whether there's any column in that table(s) which relates to date/id value. this is to determine what will be value for the columns at the current period under consideration. Or if you've a different logic of finding current values for them, please specify

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000