Column X appears twice in the result list | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Column X appears twice in the result list

Hi all The Stored Procedure runs fine without any errors.
However while executing it I get an error : Column X appears twice in the result list.
I have thoroughly checked the SP. Please help if anyone of u knows the remedy or direction of approach Thanks
Welcome to the forum. Strange error!
Is it possible to post the code here for a checkout. BTW what is the Service pack level on SQL? Satya SKJ
Microsoft SQL Server MVP
Writer, Contributing Editor & Moderator
http://www.SQL-Server-Performance.Com
@http://www.askasqlguru.com/ This posting is provided AS IS with no rights for the sake of knowledge sharing. Knowledge is of two kinds. We know a subject ourselves or we know where we can find information on it.
By any chance is this stored procedure trying to insert data via a view? The following, for example, is raising this error message:
USE tempdb
GO
CREATE TABLE t
(
c1 INT,
c2 INT
)
GO
CREATE VIEW dbo.tV
AS
SELECT c1, c1 AS c2
FROM t
GO INSERT INTO tV SELECT 1, 1 DROP VIEW dbo.tV
DROP TABLE dbo.t Msg 264, Level 16, State 1, Line 2
Column name ‘c1’ appears more than once in the result column list.

Frank Kalis
Microsoft SQL Server MVP
Contributing Editor, Writer & Forum Moderatorhttp://www.sql-server-performance.com
Webmaster:http://www.insidesql.de
Another example Select col from
(
select 1 as col, 2 as col
) T
Madhivanan Failing to plan is Planning to fail
showing us your sproc would be easiest to find out what’s wrong. _______________________________________________
Causing trouble since 1980
blog:http://weblogs.sqlteam.com/mladenp
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by Madhivanan</i><br /><br />Another example<br /><br />Select col from<br />(<br />select 1 as col, 2 as col<br />) T<br /><br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br />Great example! [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br /><br /><br />–<br />Frank Kalis<br />Microsoft SQL Server MVP<br />Contributing Editor, Writer & Forum Moderator<a target="_blank" href=http://www.sql-server-performance.com>http://www.sql-server-performance.com</a><br />Webmaster:<a target="_blank" href=http://www.insidesql.de>http://www.insidesql.de</a>
hi all<br /><br />thanks for your prompt replies friends.<br />thanks satya for your warm welcome.<br /><br />At last the problem got solved<br /><br />Actually in some part of SP a single update statement is used to update many columns in a table.In that update statement one column was updated twice.Removing one of them solved the problem.<br /><br />However,when updating should not the final update only be considered?<br /><br />at least the problem is solved but if anyone knows the reason for this that why its considering the column to apper twice on double update,please share.<br /><br />Thanks [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]
quote:
However,when updating should not the final update only be considered?
What exactly do you mean by this? An SQL UPDATE operation is a set operation being successful on all involved rows or none. It isn’t evaluated on a row-by-row, or even column-by-column base.
UPDATE t
SET c1 = 1,
c1 = 2 happens at once on the logical level. Which assignment comes first, and which comes last? You cannot tell that by refering to the position of an assigment in the statement. So, there is no first or last. —
Frank Kalis
Microsoft SQL Server MVP
Contributing Editor, Writer & Forum Moderatorhttp://www.sql-server-performance.com
Webmaster:http://www.insidesql.de
Thanks frank I got your point. So on updating C1 twice in the same update results in C1 appearing twice in result set error.
]]>