|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 7:33 AM
Points: 12,
Visits: 111
|
|
Hi
i am trying to use design mode. but it is throwing error . is there other wayt to add column in exiting view ?
Thanks, Hiren
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:54 AM
Points: 37,692,
Visits: 29,951
|
|
ALTER VIEW <view name> AS <select statement here> GO
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 7:33 AM
Points: 12,
Visits: 111
|
|
Thanks for Replay but now i am getting this Error
"Msg 205, Level 16, State 1, Procedure XXX#, Line 4 All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."
Thanks!!!!
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 2:54 AM
Points: 37,692,
Visits: 29,951
|
|
Error's pretty clear. When using a union, intersect or except all the queries must have the same number of columns
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 7:33 AM
Points: 12,
Visits: 111
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, January 15, 2013 11:11 AM
Points: 1,945,
Visits: 2,782
|
|
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."!
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.
(<table expr #1> [UNION | INTERSECT | EXCEPT] [ALL] <table expr #2>) [AS] <table name> (<column list>)
Books in Celko Series for Morgan-Kaufmann Publishing Analytics and OLAP in SQL Data and Databases: Concepts in Practice Data, Measurements and Standards in SQL SQL for Smarties SQL Programming Style SQL Puzzles and Answers Thinking in Sets Trees and Hierarchies in SQL
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, May 06, 2013 7:33 AM
Points: 12,
Visits: 111
|
|
| Thank You For Repaly!!!!!
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 4:39 PM
Points: 1,320,
Visits: 1,772
|
|
CELKO (12/27/2012)
All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists."! 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. (<table expr #1> [UNION | INTERSECT | EXCEPT] [ALL] <table expr #2>) [AS] <table name> (<column list>)
No you don't for SQL Server. The first query provides all the column names.
SQL DBA,SQL Server MVP('07, '08, '09) One man with courage makes a majority. Andrew Jackson
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Yesterday @ 10:54 PM
Points: 330,
Visits: 948
|
|
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 <header>, correct?
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 4:39 PM
Points: 1,320,
Visits: 1,772
|
|
dan-572483 (1/2/2013) 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 <header>, correct?
You don't need the AS header in SQL Server at all. SQL gets the result column names from the first query in a UNION. The others can have different column names -- or no column names at all.
SELECT 1 AS a, 2 AS b union all select 3 as c, 4 as d union all select 5 as e, 6 as f union all select 7, 8
SQL DBA,SQL Server MVP('07, '08, '09) One man with courage makes a majority. Andrew Jackson
|
|
|
|