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

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jim Horn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
Seven price

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?
Jim Horn

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'.
ASKER
Seven price

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
Seven price

Every time it finds a different row that is new it will add 1.
ASKER
Seven price

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
Jim Horn

>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?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.