Posted on August 14, 2008 by Balaji Ramesh
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 power of two [...]
Filed under: Microsoft, SQL, SQL Server, Technical | Leave a Comment »
Posted on June 5, 2008 by Balaji Ramesh
Using Persited Columns in SQL Server 2005 via t-sql and sql server management studio
Filed under: Code, Microsoft, Performance, SQL, SQL Server, T-SQL, Technical | Tagged: Computed Column, Management Studio, Persisted, SQL Server | 3 Comments »
Posted on April 14, 2008 by Balaji Ramesh
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 = ”SELECT @t = @t + ‘, [...]
Filed under: SQL, SQL Server, T-SQL, Technical | Leave a Comment »