how to updat a column from start point
-
hi to all i want to update a column from start point for example i want to update from 10 .how can i do this columns mycolumn Row1 10 Row2 11 Row3 12 . . . . . .
I'm not sure if I understood you correctly, but you can use the UPDATE statement with a WHERE Clause to control which rows are updated.
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn = 10
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn > 10
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn BETWEEN 10 AND 12
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn IN (10, 12, 15, 30)
-
I'm not sure if I understood you correctly, but you can use the UPDATE statement with a WHERE Clause to control which rows are updated.
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn = 10
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn > 10
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn BETWEEN 10 AND 12
UPDATE MyTable SET Column1 = 'Value1' WHERE mycolumn IN (10, 12, 15, 30)
-
i want to update mycolumn with 10,11,12,..... assume that my table have 100 row then mycolumn with 10,11,...,110 thanks for answer
Still not clear. Update your question with sample data(like BEFORE and AFTER format) with clear explanation. Take your time. before
A B
1 1
2 2after
A B
2 2
3 3thatraja
-
hi to all i want to update a column from start point for example i want to update from 10 .how can i do this columns mycolumn Row1 10 Row2 11 Row3 12 . . . . . .
If ye be using SQL Server, then seek thee the
ROW_NUMBER
function. If not, then at least tell us which database system you are using.You'll never get very far if all you do is follow instructions.
-
Still not clear. Update your question with sample data(like BEFORE and AFTER format) with clear explanation. Take your time. before
A B
1 1
2 2after
A B
2 2
3 3thatraja
-
UPDATE TableName SET ColumnB = ColumnA + 9
I suggest you to spend more time on SQL basics, it'll save you lot of time.
thatraja
-
UPDATE TableName SET ColumnB = ColumnA + 9
I suggest you to spend more time on SQL basics, it'll save you lot of time.
thatraja
-
ok but this is just a sample . in column A i have a uniqueidentifier value .how can i write same tsql code that you write? befor A B ---- Guid Null Guid Null . . . . . . after A B ----- Guid 10 Guid 11 , . , . , .
:| This is why should you include all details in your question when you post. You have wasted your time almost 8 hrs. Already @PIEBALDconsult gave you answer[^] by simple guess. Check this thread SQL Update with row_number()[^]
thatraja
-
If ye be using SQL Server, then seek thee the
ROW_NUMBER
function. If not, then at least tell us which database system you are using.You'll never get very far if all you do is follow instructions.
-
ok thanks for your time. i solved it by code similar this select *,ROW_NUMBER() OVER (ORDER BY [Guid] DESC) + 10 AS RN from tblTest
psst see the little arrow that appears next to the post - click that in appreciation of Piebalds help :)
Never underestimate the power of human stupidity RAH
-
Hi, Try this : ColumnA is the primary key of table : tableName
UPDATE tableName SET columnB = 9 + t2.RowNum FROM tableName t1 INNER JOIN (
SELECT ROW_NUMBER() OVER (ORDER BY columnA) RowNum,columnA FROM tableName) t2 ON t1.columnA = t2.columnA -
hi to all i want to update a column from start point for example i want to update from 10 .how can i do this columns mycolumn Row1 10 Row2 11 Row3 12 . . . . . .
Hi, Try this : ColumnA is the primary key of table : tableName
UPDATE tableName SET columnB = 9 + t2.RowNum FROM tableName t1 INNER JOIN (
SELECT ROW_NUMBER() OVER (ORDER BY columnA) RowNum,columnA FROM tableName) t2 ON t1.columnA = t2.columnA