Query for Powers of 2 in SQL Server 2005

I had a table with two columns: ID and Description. The task was to display the description of all elements whose ID is a power of two. Here’s the query that let me accomplish that: SELECT ID, Desc FROM tblBits WHERE ID > 0 AND ID & (ID-1) = 0 How does this work? Every [...]

Computed Columns in SQL Server 2005

Using Persited Columns in SQL Server 2005 via t-sql and sql server management studio

Concatenating column values in SQL Server 2000/2005

If you want to concatenate values from a specific column like for example: Table=====1    One2    Two3    Three4    Four to the following: Output======One, Two, Three, Four Here is a simple way to do it: SQL Server 2005: SELECT STUFF(SELECT ‘, ‘ + ColumnName FROM TableName FOR XML PATH(”),1,2,”) SQL Server 2000: DECLARE @t varchar(4000)SET @t = [...]

Follow

Get every new post delivered to your Inbox.