if not exists (select * from systable t join syscolumn c on t.table_id = c.table_id and
    LCase(table_name) = LCase('Printers') and LCase(column_name) = LCase('FP_SALE_NOM')) then
  alter table printers
  add FP_SALE_NOM Varchar(7) 
end if

GO

if not exists (select * from systable t join syscolumn c on t.table_id = c.table_id and
    LCase(table_name) = LCase('Printers') and LCase(column_name) = LCase('FP_Fiscal_NOM')) then
  alter table printers
  add FP_Fiscal_NOM Varchar(8) 
end if

GO

if not exists (select * from systable t join syscolumn c on t.table_id = c.table_id and
    LCase(table_name) = LCase('Printers') and LCase(column_name) = LCase('FP_SERIAL_NOM')) then
  alter table Printers
  add FP_SERIAL_NOM Varchar(8)
end if

GO

if not exists (select * from systable t join syscolumn c on t.table_id = c.table_id and
    LCase(table_name) = LCase('Printers') and LCase(column_name) = LCase('FDCommProtocol')) then
  alter table Printers  
  add FDCommProtocol Varchar(20);
end if

GO

if exists(select * from Printers where Trim(IsNull(Driver,'')) = 'FP1000' and Trim(IsNull(FDCommProtocol,'')) = '') then
 delete from Printers where Trim(IsNull(Driver,'')) = 'FP1000' and Trim(IsNull(FDCommProtocol,'')) = ''
end if

GO

if (not exists(select * from Printers where LCase(Name) = LCase('DatecsFP') and LCase(Driver)=LCase('FP1000'))) then   
  insert into Printers ("Name", "Driver", "Port", "File","Options",
  "Header", "Footer", "Aktiv", "TextWidth", "DirectPrint", "ReCoder", "Body", "Description", "N", "FDCommProtocol") 
  values('DatecsFP', 'FP1000', '1', '', 'BAUDRATE=115
FISCTOTAL=1
OPERATORCODE=1
PASSWORD=0', '', '', 1, 36, 1, '1', '', '', (select IsNull(max(n),0)+1 from  Printers ), 'Datecs')
end if

GO

if (not exists(select * from Printers where LCase(Name) = LCase('DatecsCR') and LCase(Driver)=LCase('FP1000'))) then   
  insert into Printers ("Name", "Driver", "Port", "File","Options",
  "Header", "Footer", "Aktiv", "TextWidth", "DirectPrint", "ReCoder", "Body", "Description", "N", "FDCommProtocol") 
  values('DatecsCR', 'FP1000', '1', '', 'BAUDRATE=115
FISCTOTAL=1
OPERATORCODE=1
PASSWORD=0', '', '', 1, 36, 1, '1', '', '', (select IsNull(max(n),0)+1 from Printers ), 'DatecsDP25')
end if

GO

if (not exists(select * from Printers where LCase(Name) = LCase('EltradeFP') and LCase(Driver)=LCase('FP1000'))) then   
  insert into Printers ("Name", "Driver", "Port", "File","Options",
  "Header", "Footer", "Aktiv", "TextWidth", "DirectPrint", "ReCoder", "Body", "Description", "N", "FDCommProtocol") 
  values('EltradeFP', 'FP1000', '1', '', 'BAUDRATE=115
FISCTOTAL=1', '', '', 1, 36, 1, '1', '', '', (select IsNull(max(n),0)+1 from Printers ), 'Eltrade')
end if

GO

if (not exists(select * from Printers where LCase(Name) = LCase('DaisyCR') and LCase(Driver)=LCase('FP1000'))) then   
  insert into Printers ("Name", "Driver", "Port", "File","Options",
  "Header", "Footer", "Aktiv", "TextWidth", "DirectPrint", "ReCoder", "Body", "Description", "N", "FDCommProtocol") 
  values('DaisyCR', 'FP1000', '1', '', 'BAUDRATE=115
FISCTOTAL=1
OPERATORCODE=1
PASSWORD=0', '', '', 1, 36, 1, '1', '', '', (select IsNull(max(n),0)+1 from Printers ), 'Daisy')
end if

GO

if (not exists(select * from Printers where LCase(Name) = LCase('IncotexCR') and LCase(Driver)=LCase('FP1000'))) then   
  insert into Printers ("Name", "Driver", "Port", "File","Options",
  "Header", "Footer", "Aktiv", "TextWidth", "DirectPrint", "ReCoder", "Body", "Description", "N", "FDCommProtocol") 
  values('IncotexCR', 'FP1000', '1', '', 'BAUDRATE=115
FISCTOTAL=1
OPERATORCODE=1
PASSWORD=0', '', '', 1, 36, 1, '1', '', '', (select IsNull(max(n),0)+1 from Printers ), 'Incotex')
end if

GO

if (not exists(select * from Printers where LCase(Name) = LCase('TremolCR') and LCase(Driver)=LCase('FP1000'))) then   
  insert into Printers ("Name", "Driver", "Port", "File","Options",
  "Header", "Footer", "Aktiv", "TextWidth", "DirectPrint", "ReCoder", "Body", "Description", "N", "FDCommProtocol") 
  values('TremolCR', 'FP1000', '1', '', 'BAUDRATE=115
FISCTOTAL=1
OPERATORCODE=1
PASSWORD=0', '', '', 1, 36, 1, '1', '', '', (select IsNull(max(n),0)+1 from Printers ), 'Tremol')
end if

GO

if (not exists(select * from Printers where LCase(Name) = LCase('DatecsCRX') and LCase(Driver)=LCase('FP1000'))) then   
  insert into Printers ("Name", "Driver", "Port", "File","Options",
  "Header", "Footer", "Aktiv", "TextWidth", "DirectPrint", "ReCoder", "Body", "Description", "N", "FDCommProtocol") 
  values('DatecsCRX', 'FP1000', '1', '', 'BAUDRATE=115
FISCTOTAL=1
OPERATORCODE=1
PASSWORD=0', '', '', 1, 30, 1, '1', '', '', (select IsNull(max(n),0)+1 from  Printers ), 'DatecsDP25X')
end if

GO

if (not exists (select Printer from PrintersPayCommands where Printer='FP1000' and PayType=1)) then
  insert into PrintersPayCommands(N, Printer, PayType, Command) values((select max(N)+1 from PrintersPayCommands), 'FP1000', 1, 'P')
end if

GO

if (not exists (select Printer from PrintersPayCommands where Printer='FP1000' and PayType=4)) then
  insert into PrintersPayCommands(N, Printer, PayType, Command) values((select max(N)+1 from PrintersPayCommands), 'FP1000', 4, 'N')
end if

GO

if (not exists (select Printer from PrintersPayCommands where Printer='Tremol' and PayType=1)) then
  insert into PrintersPayCommands(N, Printer, PayType, Command) values((select max(N)+1 from PrintersPayCommands), 'Tremol', 1, '0')
end if

GO

if (not exists (select Printer from PrintersPayCommands where Printer='Tremol' and PayType=4)) then
  insert into PrintersPayCommands(N, Printer, PayType, Command) values((select max(N)+1 from PrintersPayCommands), 'Tremol', 4, '7')
end if


GO

if (not exists (select Printer from PrintersPayCommands where Printer='DatecsX' and PayType=1)) then
  insert into PrintersPayCommands(N, Printer, PayType, Command) values((select max(N)+1 from PrintersPayCommands), 'DatecsX', 1, '0')
end if

GO

if (not exists (select Printer from PrintersPayCommands where Printer='DatecsX' and PayType=4)) then
  insert into PrintersPayCommands(N, Printer, PayType, Command) values((select max(N)+1 from PrintersPayCommands), 'DatecsX', 4, '1')
end if

GO

