Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 entering current date

Author  Topic 

ausla
Starting Member

7 Posts

Posted - 2012-07-11 : 23:47:35
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
Constraint Violating Yak Guru

274 Posts

Posted - 2012-07-12 : 05:45:04
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

22864 Posts

Posted - 2012-07-12 : 09:23:32
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

277 Posts

Posted - 2012-07-12 : 09:30:32
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

52326 Posts

Posted - 2012-07-12 : 09:33:46
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 - 2012-07-12 : 19:21:46
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

52326 Posts

Posted - 2012-07-12 : 20:16:24
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 - 2012-07-13 : 00:53:01
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

52326 Posts

Posted - 2012-07-13 : 10:08:37
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
   

- Advertisement -