Skip to content

Tag: sql-server

IF when zero result from another Stored Procedure

I have a Stored Procedure which contains an Insert statement on it. From the above Stored Procedure, I want to have a condition from result of another Stored Procedure. With the following action: So, if cBranch is zero. Then execute Sp1 else do nothing. Need advice please. Really appreciated. Answer Try This:

Merge lines over timespan in SCD2 table

I’m having the following table sourced from a SCD2 table. From this source table, I have selected only a few columns, which reults in several lines looking exactly similar. I want to remove the unnecessary lines, those that contain the same data, and have the ValidFrom column showing the first value and…

Get only list of user with latest update by days

I am struggling to write a query to display list of users that check-in in a day, but if the same user check-in twice or more, it would take the latest in a day. For example user A check-in in the morning, then check-in again in the evening, then the system will display only his latest check-in in the list

sys.tables vs COUNT

I have a variable @tableName (NVARCHAR(255)) that is name of a table. I’m trying to perform an action if data exists in the the table. There are two ways to check this. Method #1 (bulky) Method #2 (clean) Are methods #1 and #2 doing the exact same thing? Is it safe to use method #2? Can there be case wh…