Blog

SQL – Create a table if it doesn’t exist

Posted On:

strSQL="IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[dbo].[TBLTempPrices]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1) CREATE TABLE [TBLTempPrices]( " &_
				"[VersionCode] [varchar](25) NULL," &_
				"[Quantity1] [int] NULL," &_
			"[Price1] [float] NULL," &_
			"[Quantity2] [int] NULL," &_
			"[Price2] [float] NULL," &_
			"[Quantity3] [int] NULL," &_
			"[Price3] [float] NULL," &_
			"[Quantity4] [int] NULL," &_
			"[Price4] [float] NULL," &_
			"[Quantity5] [int] NULL," &_
			"[Price5] [float] NULL," &_
			"[Quantity6] [int] NULL," &_
			"[Price6] [float] NULL)"

Comments