*** Danger Will Robinson - Untested Code ahead ***

create table ##tempTblBusiness (
    ident         int IDENTITY(1,1),
    company          varchar(32)
)
go

insert into ##tempTblBusiness
select distinct company

go

update table tblBusiness
set companyId = b.ident
from tblBusiness a
inner join
##tempTblBusiness b
on a.company = b.company

go

Marlon



Luce, Greg wrote:

>OK, I tried asking this on SQL Team and nobody understood. I want to
>populate a new column in my tblBusiness called companyid. If there are 5
>records for "Publix" I want all 5 to have the same companyid. I could do it
>using CF very easily like this:
><cfquery name="Q1" datasource="FL100">
>       SELECT    distinct company AS company
>       FROM      tblBusiness
></cfquery>
>
><cfoutput query="Q1">
>       <cfquery name="Q2">
>               UPDATE tblBusiness
>               SET companyid = #currentrow#
>               WHERE company = '#company#'
>       </cfquery>
></cfoutput>
>
>My question is how ccan I do this in query analyzer. I'm sure you can create
>loops and variables in an SQL script, I just don't know how.
>***Sterling Financial Investment Group, Inc. (SFIG) is a member of
>NASD/MSRB/NFA/SIPC.  Email transmissions may be monitored.  SFIG cannot
>accept orders to buy or sell via email.  Please visit www.mysterling.com for
>more information.***
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in 
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm

Reply via email to