| 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 pleaseMy 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? |
 |
|
|
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 variablesMadhivananFailing to plan is Planning to fail |
 |
|
|
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-------------------------- |
 |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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 |
 |
|
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
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 MVPhttp://visakhm.blogspot.com/[/quote] |
 |
|
|
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_idi 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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|