Skip to content

Tag: sql-server

SQL CASE with multiple join

I am trying to run a sql select code as below. I am trying to fetch the trans_date which will either be in asutrans or asuhistr. But the below code doesnt give me any value and nor does it fail. Do you think we can use CASE statement like that? If I run the codes separately, then it does give

Looping in SQL with TempTable

I am new to SQL Server, can you please help me to write query for my scenario? I have this Table1 : Input to my stored procedure is a PolicyNumber e.g 1234 and the code should return 5 rows. I need to cover these cases: If the first payment is not cancelled, I need return that row. If the first

How to exclude a specific row from an SQL Count

I need to exclude a certain row from a COUNT in SQL Server. This is what I have: If I remove the last AND GuestStayDetails.GuestId != @GuestId; it gives me the expected COUNT however I must exclude one of the GuestIDs. Any suggestions? Answer It looks like you are looking for overlapping time intervals &#8212…