Skip to content
Advertisement

Tag: sql-server-2005

conditional unique constraint

I have a situation where i need to enforce a unique constraint on a set of columns, but only for one value of a column. So for example I have a table like Table(ID, Name, RecordStatus). RecordStatus can only have a value 1 or 2 (active or deleted), and I want to create a unique constraint on (ID, RecordStatus) only

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

SQL Statement Help – Select latest Order for each Customer

Say I have 2 tables: Customers and Orders. A Customer can have many Orders. Now, I need to show any Customers with his latest Order. This means if a Customer has more than one Orders, show only the Order with the latest Entry Time. This is how far I managed on my own: This of course returns all Customers with

Advertisement