sql - Temp table with converted values -


i want script convert table

create table #temptable ( code nvarchar(5) primary key, name nvarchar(100) )  insert #temptable (code ,name)  select st.code , st.name statictable st 

but there must change.

code must autoincremented 100

where length of code more 3, want insert there integer, when not want copy code

so

    code   name     abcd   namezxc     efgh   nameasd     ijk    nameqwe 

i want temptable records:

code name 100    namezxc 101    nameasd ijk  nameqwe 

best regards

first insert values, go , update ones len() > 3. use shady(because nvarchar , have cast) increment variable.

create table #temptable (     code nvarchar(5) primary key,     name nvarchar(100)  )  insert #temptable (code ,name)  select st.code , st.name (    select 'abcd' code, 'namezxc' name union    select 'efgh' code, 'nameasd' name union    select 'ijk' code, 'nameqwe' name  ) st  declare @vintcounter nvarchar(5) set @vintcounter = n'99'  update #temptable      set @vintcounter = code = cast(@vintcounter int) + 1 len(code) > 3  select * #temptable 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -