IF NOT EXISTS (select 1 from sysobjects where name = '(PREPARETABLENAME)')
BEGIN
CREATE TABLE [(PREPARETABLENAME)] (
	[id] int IDENTITY NOT NULL,
	[prodsubtype] char(10) not null,
	[resprodcode] varchar(13) not null,
	[code20] char(20) not null,
	[parentcode] char(20),
	[codelv]  tinyint not null,
	[lv4code] tinyint default 0 not null,
	[lv3code] tinyint default 0 not null,
	[lv2code] tinyint default 0 not null,
	[lv1code] tinyint default 0 not null,
	[smidcode] char(20),
	[lmidcode] char(20),
	[boxcode] char(20) not null,
	[codeflag] tinyint not null,
	[lineid] char(4) not null,
	[taskid] integer not null,
	[status]  tinyint not null default 0,
	[sysuserid] integer  default -1,
	[savetime]  datetime default getdate() not null,
	[updateuser] integer,
	[updatetime] datetime,
  PRIMARY KEY NONCLUSTERED ([code20])
)
CREATE CLUSTERED INDEX [IX_(PREPARETABLENAME)_pkk] ON [dbo].[(PREPARETABLENAME)](
  [taskid] ASC,
  [boxcode] ASC,
  [codelv] DESC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_(PREPARETABLENAME)_1] ON [(PREPARETABLENAME)] 
(
  [boxcode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IX_(PREPARETABLENAME)_2] ON [(PREPARETABLENAME)] 
(
  [smidcode] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

END