Avatar of Seven price
Seven priceFlag for United States of America

asked on 

msql compare same column

BEGIN

Declare @req varchar(200),
Declare @maxred varchar(200)

set @req=(select mycolumn1 from table where )

set @maxreq=(select mycolumn1 from table where)

if(@req<=@maxreq)

THEN

update

END

Open in new window

END

I have a table column name, mycolumn1.
what I would like to do is compare. if the column name changes then update 1 in another column else 0
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Jim Horn
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Seven price
Seven price
Flag of United States of America image

ASKER

well there I have the same name that repeats itself within a column. When the column name changes then I have another column in which i want to add a 1 when it changes to a new name. the column compares itself. but how do I pass the where clause?
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Tell you what, please re-ask your question, providing sample data for the 'before' and 'after' of what you're trying to pull off, and using explicit column names instead of 'another column' and 'the column'.
Avatar of Seven price
Seven price
Flag of United States of America image

ASKER

select statements will check column

@req>>mycolumn1   @maxreq>>mycolumn1        additional column value(blank)

mydata                     mydata                                1        
mydata                     mydata                                0
mydata                     mydata                                0
newdata                   newdata                               1
newdata                   newdata                               0
newdata                   newdata                               0
Avatar of Seven price
Seven price
Flag of United States of America image

ASKER

Every time it finds a different row that is new it will add 1.
Avatar of Seven price
Seven price
Flag of United States of America image

ASKER

I got it myself thanks anyway.

declare @boothTable table (BoothNameID varchar(200),RownameID varchar(20), ProductID varchar(6))
insert into @boothTable
SELECT distinct BoothName,
  rowid,
 product
  FROM tableM
ORDER BY rowid,BoothName

DECLARE Booth     CURSOR FOR
      SELECT BoothNameID,
RownameID,
     ProductID
        FROM @boothTable
--order by VendorID,BoothNameID
   --ORDER BY BoothNameID, SequenceID

--ORDER BY Grouper,sequence
OPEN Booth
FETCH NEXT FROM Booth INTO @BoothNameID, @RownameID, @ProductID

WHILE @@FETCH_STATUS = 0
BEGIN

  IF @BoothNameID = @BoothNameID2
     SET @Seq = @Seq + 1
  ELSE
     SET @Seq = 1
     
   -- This is executed as long as the previous fetch succeeds.
      UPDATE table
         SET WebSeq = @Seq
     WHERE Boothname = @BoothNameID  and RowID=@RownameID and Product = @ProductID
    -- order by rowid asc
     SET @BoothNameID2 = @BoothNameID

  FETCH NEXT FROM Booth INTO @BoothNameID,  @RownameID,@ProductID
END

CLOSE Booth
DEALLOCATE Booth
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

>Every time it finds a different row that is new it will add 1.
Since I see three rows of 'mydata', how do you determine the ordering of those three, so I know which one to add 1?  Is it just the position within the table, or is there a column somewhere that dictates the order?
Microsoft SQL Server 2005
Microsoft SQL Server 2005

Microsoft SQL Server 2005 is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning. It includes support for managing XML data and allows a database server to be exposed over web services using Tabular Data Stream (TDS) packets encapsulated within SOAP (protocol) requests.

72K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo