Skip to content
Advertisement

Tag: tsql

Difference between CTE and SubQuery?

From this post How to use ROW_NUMBER in the following procedure? There are two versions of answers where one uses a sub-query and the other uses a CTE to solve the same problem. Now then, what is the advantage of using a CTE (Common Table Expression) over a ‘sub-query`(thus, more readable what the query is actually doing) The only advantage

SQL Server 2005: Determine datatype of variable

Is it possible to determine the type of a local variable at runtime in TSQL? For example, say I wanted to do something along these lines: Or Does anyone know of any way to accomplish this? EDIT: This is not for a specific task, this is more of a general knowledge question. I do appreciate answers that indicate that the

What are the use cases for selecting CHAR over VARCHAR in SQL?

I realize that CHAR is recommended if all my values are fixed-width. But, so what? Why not just pick VARCHAR for all text fields just to be safe. Answer The general rule is to pick CHAR if all rows will have close to the same length. Pick VARCHAR (or NVARCHAR) when the length varies significantly. CHAR may also be a

SQL Server – Best way to get identity of inserted row?

What is the best way to get IDENTITY of inserted row? I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY but don’t understand the pros and cons attached to each. Can someone please explain the differences and when I should be using each? Answer @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes.

Advertisement