Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Analyzer Select Distinct

Status
Not open for further replies.

rwies

IS-IT--Management
Jun 8, 2003
41
0
0
US
I need to run a select distinct from query analyzer to update a table.

Below is my attempt that did not work.

Any ideas?

Thanks,

Ron--

insert into dbo.AccountZoneTbl0
(acct_cancelcode, AccountNumber, S_ActNbr, System_no, MAS_ZoneID, o_mas_zoneid, fmt,
[Description], GroupID, DateTimeStamp, zonestate_id,
xz, zonetbl, proctbl, mas_event, z_zoneid,
p_zoneid)

select distinct(acct_cancelcode), AccountNumber, S_ActNbr, System_no, mas_cancelcode, o_mas_zoneid, 'cid',
'Cancel', GroupID, DateTimeStamp, 'A',
1, 1, 1, groupid + 'CAL', mas_cancelcode,
mas_cancelcode

from dbo.AccountZoneTbl0
where fmt = 'cid' and cancelcode is not null
 
Code:
insert into dbo.AccountZoneTbl0
    (acct_cancelcode, AccountNumber, S_ActNbr, System_no,
     MAS_ZoneID, o_mas_zoneid, fmt, [Description], GroupID,
     DateTimeStamp, zonestate_id, xz, zonetbl, proctbl,
     mas_event, z_zoneid, p_zoneid)

select distinct
       acct_cancelcode, AccountNumber, S_ActNbr, System_no,
       mas_cancelcode, o_mas_zoneid, 'cid', 'Cancel',
       GroupID, DateTimeStamp, 'A', 1, 1, 1,
       groupid + 'CAL', mas_cancelcode, mas_cancelcode
from    dbo.AccountZoneTbl0
where    fmt = 'cid' and cancelcode is not null

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
 
Running the query you have above will insert more records into the table. It won't update the records. You'll need to write it as an update statement to update the existing records.

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Thanks to both bborissov and mrdenny.

I appreciate your assistance. I got what I needed.

Ron--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top