db2 - SQL Month comparison to declared variable -


select  sc.locationid, --here result (    if month(date()) between 8 , 12 @semterm = 's1'    else @semterm = 's2'    end if )as @semterm  student_class sc @semterm = sc.semester ; 

in db2 student management system. read access. desired outcome if jan thru june, s2 else if aug thru dec, s1. trying setup variable based on current date stamp month segregated assigned variable compared against column in student_class table.

have tried case statements no luck. unable declare @semterm without error above select statement. looked @ clause solution also. out in left field? seems simple struggling syntax. part of larger statement locationid 1 column in student_class.

you can't use if statement in simple select statement, must use case:

select      sc.locationid, --here result     case        when month(current date) between 8 , 12 's1'       when month(current date) between 1 , 6  's2'       else ''     end semterm       student_class sc 

if want find students current semester, want move case statement where clause:

select      sc.locationid, --here result     sc.semester,     ...      student_class sc      sc.semester = case                      when month(current date) between 8 , 12 's1'                     when month(current date) between 1 , 6  's2'                     end 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -