How to write this query?
-
Hello all, I have a table in which I have added new one column and now I want to add data to it. What I want is that column starting values should be from some number and end with the number of rows. Like if I have 1000 records in by table then I want this column to have values from 2200 to 2200 + 1000. I hope I made myself clear. Please help me. Thanks in advance.
-
Hello all, I have a table in which I have added new one column and now I want to add data to it. What I want is that column starting values should be from some number and end with the number of rows. Like if I have 1000 records in by table then I want this column to have values from 2200 to 2200 + 1000. I hope I made myself clear. Please help me. Thanks in advance.
declare @newValue as int set @newValue = (selex max(colname) from tablename) insert into tablename ColumnName values (@newValue+1)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
-
declare @newValue as int set @newValue = (selex max(colname) from tablename) insert into tablename ColumnName values (@newValue+1)
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
Thanks for the reply but I dont want to insert the records. I want to update one columns values which null now. How can we do this??
-
Thanks for the reply but I dont want to insert the records. I want to update one columns values which null now. How can we do this??
I don't understand good ur questions. To update columns which have null value then simple use
Update tablename where colname=null and coname=anothercondition
If this is again not help then describe in detail your case.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
-
I don't understand good ur questions. To update columns which have null value then simple use
Update tablename where colname=null and coname=anothercondition
If this is again not help then describe in detail your case.
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.
Well what I want is: Table Name: tb_Data Columns: Name1, Name2, ID Number of Records : 1000 Something like this:
Name1 Name2 ID
N1 N2 null
N3 N4 null
N3 N4 null
N3 N4 null
Like wise....
N3 N4 nullNow ID Column has null values and in ID Column I want it to get values starting from 2200 to 3200 that is records should be now as:
Name1 Name2 ID
N1 N2 2200
N3 N4 2201
N3 N4 2202
N3 N4 2203
Like wise....
N3 N4 3200Is there anyway to do it by Query as Im having records in lakhs. Thanks again.
-
Well what I want is: Table Name: tb_Data Columns: Name1, Name2, ID Number of Records : 1000 Something like this:
Name1 Name2 ID
N1 N2 null
N3 N4 null
N3 N4 null
N3 N4 null
Like wise....
N3 N4 nullNow ID Column has null values and in ID Column I want it to get values starting from 2200 to 3200 that is records should be now as:
Name1 Name2 ID
N1 N2 2200
N3 N4 2201
N3 N4 2202
N3 N4 2203
Like wise....
N3 N4 3200Is there anyway to do it by Query as Im having records in lakhs. Thanks again.
hi, Well based on your last post I have more clear your situation. It seems that you dont have increament column in table and i make fast solution,maybe is not the best solution but it will work. here is code down below,just copy-modify-paste and use in your real data
create table #TempTable ( IdentValue int IDENTITY(1,1), Name1 varchar(255), Name2 varchar(255), ID Int ) insert into #TempTable select name1,name2,id from tabela declare @i as int set @i=0 declare @startValue as int set @startValue =2200 declare @endValue as int set @endValue=3200 while @i<(select count(*) from #temptable) begin set @i=@i+1 set @startValue=@startValue+1 update #tempTable set ID=@startValue where identValue=@i end delete from tabela insert into tabela select name1,name2,id from #temptable drop table #temptable select * from tabela
I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.