Aniket Narvankar

Aniket Narvankar

  • 562
  • 2.1k
  • 605.1k

SQL QUERY Solution Needed

Jun 16 2022 8:13 AM

I have a table tblGeoLocation having 4 Columns Lat,Long,RunDate,LocType

Want to insert values from tbl1 into tblGeoLocation table. if @geolocation=0 then NULL values else the Lat,Long,LocType,RunDate values

 insert into tblGeoLocation(Lat,Long,LocType,RunDate)  

  Select  Case when @geolocation = '0' Then Null Else tbl1.GoogleLatitude END,
  Case when @geolocation = '0' Then Null Else tbl1.GoogleLongitude END,
  Case when @geolocation = '0' Then Null Else tbl1.GoogleLocationType END,
  Case when @geolocation = '0' Then Null Else tbl1.RunDate END,
  From tbl1 where Id=@Id

 

Please let me know how this can be done with out multiple else,for example case when @geolocation='0' then null is same,i do not want to write this multiple times for multiple columns. how can this be avoided. 


Answers (3)