I am new to creating stored procedures and I saw this sql below in an existing stored procedure:
IF EXISTS (SELECT * FROM table WHERE object_id = OBJECT_ID(N'stored_proc_name') AND type in (N'P', N'PC'))
DROP PROCEDURE 'stored_proc_name' Go
After some investigating I did, I found that we are using N for any unicode characters that may be present. However, I am not sure why we are using “type in (N’P’, N’PC’)”?
Can anyone please explain this construct?
Also just confirm if I am correct in my thinking about the use of N here?
Yes, the N means that the strings are unicode.
What else you have is the
inoperator, i.e.n in (n, ...)where the first operand is the fieldtypeand the values in the parentheses are two unicode strings.So, it has the same meaning as
and (type = N'P' or type = N'PC').