Skip to content

Tag: sql-server

SQL Update Only when Max Date reached

I’ve two tables like: Table1 Table2 The scenario is: If I update the Table2 on TID2 = 2, the LastStatus on Table1 shouldn’t be updated because there’s a MAX Date on Table2 with TID1=1. So LastStatus on Table1 will only updated if there’s an update on Table2 with MAX Date. Currently, I …

Case expression for null and not null columns in a table

My table: Query tried Basically I want that if there is any single null bvalue for any column in table StudentScore, then the type of that column should be null else it should be not null (note that this is part of interview question and I cannot use information_schema etc. I need to do this using case. Can a…

find missing records in corresponding tables

Let’s say I have two temp tables with data that looks like this… Here’s what I am trying to achieve 1) Exclude all records from #TEMP1 and #TEMP2 that have identical match on IdNO, CdId, ApptDate, PROC=Y I’m only interesting in finding these scenarios: 1) Find record from #Temp1 or #Te…

Joining one table twice and counting records

I have 2 tables. One is master and thee other is a lookup. TblMstr and Cmaster Tblmstr Cmaster I need to get how many Registered Nurse for each question have Strongly Agree, Disagree and Agree. Similarly for Nurse Practitioners and Pharmacists. Answer Hmmm . . . You can join twice. Once to get the occupation …