Skip to content
Advertisement

Tag: tsql

How to set multiple values inside an if else statement?

I’m trying to SET more than one value within the if else statement below, If I set one value it works, but if I set two values, it doesn’t work: Error message: “Msg 156, Level 15, State 1, Line 9 Incorrect syntax near the keyword ‘ELSE’.” However it seems to be possible to have multiple SET variables after the else;

WITH(NOLOCK) : where & when to use

I have 15 tables which are normalized to contain records and many user may be inserting/updating data in these tables( No two user can update the same record(s) simultaneously, this is restricted by client implementation). these 15 tables are updated 1 by 1 in a stored procedure. WITH(NOLOCK) is used where select statements are to avoid read locks as some

drop trigger if exists and create

I would like to check if the trigger exists on [tbl] and create another one. I tried it this way but didn’t work. What am I doing wrong? Answer The [name] field in sys.objects will contain only the actual name (i.e. trg), not including the schema (i.e. dbo in this case) or any text qualifiers (i.e. [ and ] in

T-SQL Dollar Sign In Expressions

In this answer, there is a trick which allows to use the ROW_NUMBER() windowed function with a ‘constant’ in the ORDER BY clause: After some search in Google, I can’t find what dollar sign means in this context? I’ve tried to execute a simple query: And it returns 0. Could somebody explain this? Answer It’s just a money constant (what

Do I need a where clause in a conditional UPDATE?

We imported a lot of data from another table. Now I’m trying to correct some of them. I didn’t use ELSE because many rows have valid country. My question is to know whether I need to the WHERE clause to filter the rows that will be affected? The reason I’m asking this question is that, I’ve selected into a test

Advertisement