Ok, so I'm not sure if the title is worded correctly, but I needed something so here's what I'm getting at:
I was working on a SQL stored procedure at work today and adding some more joins and columns to a Select statement that was part of a Union with another Select statement. Everything was going good until I added a Text column to the columns to return. At this point I started getting an error stating that Text columns can not be used with Distinct. The odd thing was that the Distinct keyword didn't exists in the Select statement (or anywhere in that stored procedure for that fact). I thought about it for a little bit, after messing around with the statment for a while, and realized something. A Union will not insert duplicate rows into the resultant data, it basically does a Distinct Select. Since I knew this particular Union statement would never return duplicate data, I modified it from being a standard 'Union' to a 'Union All'. I was then able to add the Text column with no problem.
Tags: Microsoft, SQL Server, SQL
0 comments:
Post a Comment