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

testing - Detect whether test has failed within fixture -

AbotX : How do you create a parallel crawler that stays on and can be added to at run time from new requests -

android - Create single AAR file from multiple modules using Gradle -