各位大大好!!小弟目前遇到一個問題,就是想做測試資料來測試的時候,一直做不出來想要的資料!!懇請大大協助小弟
以下是新增加資料的SQL
SET IDENTITY_INSERT TestTable ON
declare @i int
set @i=1
while @i<=1000
begin
insert into TestTable([id], FirstName, LastName, Country,Note) values(@i, 'FirstName_XXX','LastName_XXX','Country_XXX','Note_XXX')
set @i=@i+1
end
SET IDENTITY_INSERT TestTable OFF
目前是希望跑出來的資料可以是
1 LastName_0001,Country_0001,Note_0001
2 LastName_0002,Country_0002,Note_0002
類似這樣的排法!!!
原本小弟是ˊ直接在valur 後面 直接使用 +@i的方法,但是卻出現類型錯誤!!
不知是否有其他比較好的 法解決呢??
Use this..
<pre class="c" name="code">
SET IDENTITY_INSERT TestTable ON
declare @i int
declare @t varchar(4)
set @i=1
while @i<=1000
begin
set @t = Replicate('0', 4-LEN(@i)) + CAST(@i as varchar(4))
insert into TestTable([id], FirstName, LastName, Country,Note) values(@i, 'FirstName_' + @t,'LastName_' + @t,'Country_' + @t,'Note_' + @t)
set @i=@i+1
end
SET IDENTITY_INSERT TestTable OFF