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
LVL 9
Seven priceFull StackAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Not really following what you are asking, but here's a shot (replace x with your WHERE criteria)...
Declare @req varchar(200), @maxred varchar(200)

select @req= mycolumn1 from table where x

select @maxreq = mycolumn1 from table where x

UPDATE table SET another_column CASE WHEN @req<=@maxreq THEN 1 ELSE 0 END WHERE x

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Seven priceFull StackAuthor Commented:
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?
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
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'.
0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Seven priceFull StackAuthor Commented:
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
0
Seven priceFull StackAuthor Commented:
Every time it finds a different row that is new it will add 1.
0
Seven priceFull StackAuthor Commented:
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
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>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?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.