Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

i want to add column in exiting view Expand / Collapse
Author
Message
Posted Thursday, December 27, 2012 9:53 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 6:57 AM
Points: 21, Visits: 306
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
Post #1400685
Posted Thursday, December 27, 2012 10:05 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 1:14 PM
Points: 40,615, Visits: 37,081
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

Post #1400690
Posted Thursday, December 27, 2012 11:00 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 6:57 AM
Points: 21, Visits: 306
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!!!!
Post #1400708
Posted Thursday, December 27, 2012 11:06 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 1:14 PM
Points: 40,615, Visits: 37,081
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

Post #1400709
Posted Thursday, December 27, 2012 11:10 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 6:57 AM
Points: 21, Visits: 306
Thank You!!!
Post #1400711
Posted Thursday, December 27, 2012 5:23 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: 2 days ago @ 12:12 PM
Points: 1,945, Visits: 3,180
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
Post #1400759
Posted Friday, December 28, 2012 8:52 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 30, 2014 6:57 AM
Points: 21, Visits: 306
Thank You For Repaly!!!!!
Post #1400944
Posted Monday, December 31, 2012 2:31 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 3:26 PM
Points: 2,330, Visits: 3,509
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)

Carl Sagan said: "There is no such thing as a dumb question." Sagan obviously never watched a congressional hearing!
Post #1401508
Posted Wednesday, January 2, 2013 10:55 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 10:51 AM
Points: 558, Visits: 1,652
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?

Post #1401973
Posted Wednesday, January 2, 2013 12:39 PM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 3:26 PM
Points: 2,330, Visits: 3,509
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)

Carl Sagan said: "There is no such thing as a dumb question." Sagan obviously never watched a congressional hearing!
Post #1402043
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse