﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / T-SQL (SS2K8)  / i want to add column in exiting view / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 19 Jun 2013 11:26:58 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>[quote][b]dan-572483 (1/2/2013)[/b][hr]If all the queries in combined by the UNION statement are quering the same table (or differenet tables but the coumn names are the same), then you shoudn't need to use AS &amp;lt;header&amp;gt;, correct?[/quote]You don't need the AS header in SQL Server at all.  SQL gets the result column names from the [i]first[/i] query in a UNION.  The others can have different column names -- or no column names at all.[code="sql"]SELECT 1 AS a, 2 AS bunion allselect 3 as c, 4 as dunion allselect 5 as e, 6 as f union allselect 7, 8[/code]</description><pubDate>Wed, 02 Jan 2013 12:39:25 GMT</pubDate><dc:creator>ScottPletcher</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>If all the queries in combined by the UNION statement are quering the same table (or differenet tables but the coumn names are the same), then you shoudn't need to use AS &amp;lt;header&amp;gt;, correct?</description><pubDate>Wed, 02 Jan 2013 10:55:56 GMT</pubDate><dc:creator>dan-572483</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>[quote][b]CELKO (12/27/2012)[/b][hr][quote]All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."![/quote]The term for this is "union compatible" and it means that both tables in a set operation have to have the same number of columns and those columns have to match by data type and by position. Further more, the result of a set operation is a table whose columns  have no names. This means that you need to write an AS clause to name them.  (&amp;lt;table expr #1&amp;gt;   [UNION | INTERSECT | EXCEPT] [ALL] &amp;lt;table expr #2&amp;gt;) [AS] &amp;lt;table name&amp;gt; (&amp;lt;column list&amp;gt;)[/quote]No you don't for SQL Server.  The first query provides all the column names.</description><pubDate>Mon, 31 Dec 2012 14:31:13 GMT</pubDate><dc:creator>ScottPletcher</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>Thank You For Repaly!!!!!</description><pubDate>Fri, 28 Dec 2012 08:52:36 GMT</pubDate><dc:creator>hpatelc</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>[quote]All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."![/quote]The term for this is "union compatible" and it means that both tables in a set operation have to have the same number of columns and those columns have to match by data type and by position. Further more, the result of a set operation is a table whose columns  have no names. This means that you need to write an AS clause to name them.  (&amp;lt;table expr #1&amp;gt;   [UNION | INTERSECT | EXCEPT] [ALL] &amp;lt;table expr #2&amp;gt;) [AS] &amp;lt;table name&amp;gt; (&amp;lt;column list&amp;gt;)</description><pubDate>Thu, 27 Dec 2012 17:23:09 GMT</pubDate><dc:creator>CELKO</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>Thank You!!!</description><pubDate>Thu, 27 Dec 2012 11:10:19 GMT</pubDate><dc:creator>hpatelc</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>Error's pretty clear. When using a union, intersect or except all the queries must have the same number of columns</description><pubDate>Thu, 27 Dec 2012 11:06:31 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>Thanks for Replay but now i am getting this Error"Msg 205, Level 16, State 1, Procedure XXX#, Line 4All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."Thanks!!!!</description><pubDate>Thu, 27 Dec 2012 11:00:57 GMT</pubDate><dc:creator>hpatelc</dc:creator></item><item><title>RE: i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>ALTER VIEW &amp;lt;view name&amp;gt;AS&amp;lt;select statement here&amp;gt;GO</description><pubDate>Thu, 27 Dec 2012 10:05:34 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>i want to add column in exiting view</title><link>http://www.sqlservercentral.com/Forums/Topic1400685-392-1.aspx</link><description>Hii am trying to use design mode. but it is throwing error . is there other wayt to add column in exiting view ?Thanks,Hiren</description><pubDate>Thu, 27 Dec 2012 09:53:35 GMT</pubDate><dc:creator>hpatelc</dc:creator></item></channel></rss>