基本信息
源码名称:把sqlserver数据转换为insert的sql脚本
源码大小:0.83M
文件格式:.rar
开发语言:Pascal
更新时间:2025-06-16
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
把sqlserver数据转换为insert的sql脚本
function ExportDatabyInsert(ado: TADOQuery; tn: string): TStrings;
var
i: integer;
Sql, tmp1, tmp2, Flag, flag1: string;
b: Boolean;
begin
b := false;
Result := TStringList.Create;
ado.First;
while not ado.Eof do begin
Sql := 'insert into ' tn '(';
tmp1 := '';
tmp2 := '';
for i := 0 to ado.FieldCount - 1 do
begin
if i = ado.FieldCount - 1 then //当取最后一个字段时
begin
Flag := ')';
Flag1 := ');';
end
else
begin
Flag := ',';
Flag1 := ',';
end;
//--------------------------------------------------------
if ado.Fields[i].ReadOnly then
begin
b := True;
end;
tmp1 := tmp1 ado.Fields[i].FieldName Flag;
if ado.Fields[i].IsNull then //当值数据字段值为空时
tmp2 := tmp2 'null' Flag1
else begin
if ado.Fields[i].DataType in [ftSmallint, ftInteger, ftFloat, ftBCD, ftCurrency, ftBytes, ftVarBytes] then
tmp2 := tmp2 ado.Fields[i].AsString Flag1
else if ado.Fields[i].DataType in [ftBoolean] then
tmp2 := tmp2 BoolToStr(ado.Fields[i].asBoolean) Flag1
else if ado.Fields[i].DataType in [ftBlob] then
tmp2 := tmp2 '0x' StrToHex(ado.Fields[i].AsVariant) Flag1
else tmp2 := tmp2 QuotedStr(ado.Fields[i].AsString) Flag1 '';
end;
//--------------------------------------------------------
end;
Sql := Sql tmp1 ' Values(' tmp2;
Result.Add(Sql);
ado.Next;
end;
if b then
begin
Result.Insert(0, 'SET IDENTITY_INSERT ' tn ' ON');
Result.Insert(Result.Count, 'SET IDENTITY_INSERT ' tn ' OFF');
end;
end;
把sqlserver数据转换为insert的sql脚本
function ExportDatabyInsert(ado: TADOQuery; tn: string): TStrings;
var
i: integer;
Sql, tmp1, tmp2, Flag, flag1: string;
b: Boolean;
begin
b := false;
Result := TStringList.Create;
ado.First;
while not ado.Eof do begin
Sql := 'insert into ' tn '(';
tmp1 := '';
tmp2 := '';
for i := 0 to ado.FieldCount - 1 do
begin
if i = ado.FieldCount - 1 then //当取最后一个字段时
begin
Flag := ')';
Flag1 := ');';
end
else
begin
Flag := ',';
Flag1 := ',';
end;
//--------------------------------------------------------
if ado.Fields[i].ReadOnly then
begin
b := True;
end;
tmp1 := tmp1 ado.Fields[i].FieldName Flag;
if ado.Fields[i].IsNull then //当值数据字段值为空时
tmp2 := tmp2 'null' Flag1
else begin
if ado.Fields[i].DataType in [ftSmallint, ftInteger, ftFloat, ftBCD, ftCurrency, ftBytes, ftVarBytes] then
tmp2 := tmp2 ado.Fields[i].AsString Flag1
else if ado.Fields[i].DataType in [ftBoolean] then
tmp2 := tmp2 BoolToStr(ado.Fields[i].asBoolean) Flag1
else if ado.Fields[i].DataType in [ftBlob] then
tmp2 := tmp2 '0x' StrToHex(ado.Fields[i].AsVariant) Flag1
else tmp2 := tmp2 QuotedStr(ado.Fields[i].AsString) Flag1 '';
end;
//--------------------------------------------------------
end;
Sql := Sql tmp1 ' Values(' tmp2;
Result.Add(Sql);
ado.Next;
end;
if b then
begin
Result.Insert(0, 'SET IDENTITY_INSERT ' tn ' ON');
Result.Insert(Result.Count, 'SET IDENTITY_INSERT ' tn ' OFF');
end;
end;