When I have an SQL query with a GROUP BY clause, It is often very useful to see some of the un-grouped values for easier debugging. My question is, how can I select a string that will be composed of the un-grouped values. For example, in the following code: I would like to have a way to select a string
Tag: sql-server-2008-r2
SQL Find duplicate sets
given this Schema: table tblSET SetID int PK SetName nvarchar(100) Table tblSetItem SetID int PK ItemID int PK tblSetItem.SetID is a FK into the tblSet Table. Some data: …
Best Practice For Lookup Tables In SQL
I am fairly new to SQL so apologies if this questions sounds odd. I keep coming across the issue of poor data. As an example London could be stored as LON, London UK, London England etc. Prior to …
SQL Split Function and Ordering Issue?
I have the following Split function, When I write, This will give me, I need to maintain the order. Answer A simpler function: Sample usage: Or to return orders from a table ordered by input:
SQL Server – Create a copy of a database table and place it in the same database?
I have a table ABC in a database DB. I want to create copies of ABC with names ABC_1, ABC_2, ABC_3 in the same DB. How can I do that using either Management Studio (preferably) or SQL queries ? This is for SQL Server 2008 R2. Answer Use SELECT … INTO: This will create a new table ABC_1 that has
IIF(…) not a recognized built-in function
I’m trying to use this in Microsoft SQL Server 2008 R2: But I get an error: IIF(…) is not a recognized built-in function name Is IIF() only compatible with a later version? Is there an alternate function I can use? Answer IIF comes from SQL 2012. Before then, you can use CASE:
How to return default value from SQL query
Is there any easy way to return single scalar or default value if query doesn’t return any row? At this moment I have something like this code example: How to do that in better way without using IF-ELSE? Answer Assuming the name is not nullable and that Id is unique so can match at most one row.
Recover sa password [closed]
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it’s on-topic for Stack Overflow. Closed 10 years ago. Improve this question I have a computer which was used by another employee. SQL Server 2008 R2 was installed but I don’t know the ‘sa’ password. When I try to alter
How to rewrite IS DISTINCT FROM and IS NOT DISTINCT FROM in SQL Server 20008R2?
How do you rewrite expressions containing the standard IS DISTINCT FROM and IS NOT DISTINCT FROM operators in the SQL implementation in Microsoft SQL Server 2008R2 that does not support them? Answer The IS DISTINCT FROM predicate was introduced as feature T151 of SQL:1999, and its readable negation, IS NOT DISTINCT FROM, was added as feature T152 of SQL:2003. The
Finding rows with consecutive increase in the values of a column
I have a sql table that stores the daily prices of stocks. New records are inserted every day after the market closes. I want to find the stocks that have consecutive increases in price. The table has lots of columns, but this is the relevant subset: The quoteid column is a primary key. In the table, the closing price of