SQL Server: how to set if condition in where -


i need sql server query. have 3 tables documents, modules , folders.

document table

id title type data folderid 

module table

id label moduleid folderid 

folder table

id label 

if type = 1 in document table, want folderid module table otherwise should take id itself

i tried below query

select  m.*   modules m   left join documents ed on cast(m.moduleid varchar) = ed.data   m.folderid = 35 or ed.folderid =35 

but not able write if condition in can tell me how can that?

thanks in advance

another option case expression.

select  m.* modules m left join documents ed on cast(m.moduleid varchar) = ed.data case when type = 1      m.folderid      else ed.folderid      end = 35 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -