2017-06-14 66 views
0

我在SQL Server中有兩個表,名字分別爲tblGlobalGSTRatesMasterItblGlobalGSTRatesMasterII。現在我想將tblGlobalGSTRatesMasterI中的第一行復制到表tblGlobalGSTRatesMasterII - 請告訴我如何在SQL Server中實現這一點。將表中的第一行復制到SQL Server中的另一個表中

這兩個表具有相同的結構。

這是表tblGlobalGSTRatesMasterI的結構:

CREATE TABLE [master].[tblGlobalGSTRatesMasterI] 
(
    [MasterId] [bigint] IDENTITY(1,1) NOT NULL, 
    [HSNSAC] [varchar](10) NULL, 
    [Description] [varchar](500) NULL, 
    [UnitofMeasurement] [varchar](30) NULL, 
    [GstIGSTRt] [decimal](6, 2) NULL, 
    [GstCGSTRt] [decimal](6, 2) NULL, 
    [GstSGSTRt] [decimal](6, 2) NULL, 
    [GstUTGSTRt] [decimal](6, 2) NULL, 
    [GstCessRt] [decimal](6, 2) NULL, 
    [ExmtCircularNumber] [varchar](20) NULL, 
    [ExmtCircularDate] [varchar](10) NULL, 
    [ExmtEffectiveDate] [varchar](10) NULL, 
    [ExmtGstIGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstCGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstSGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstUTGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstCessRt] [decimal](6, 2) NULL, 
    [TdsIGSTRt] [decimal](6, 2) NULL,  
    [TdsCGSTRt] [decimal](6, 2) NULL, 
    [TdsSGSTRt] [decimal](6, 2) NULL, 
    [TdsUTGSTRt] [decimal](6, 2) NULL, 
    [TdsCessRt] [decimal](6, 2) NULL, 
    [ExmtTdsCircularNumber] [varchar](20) NULL, 
    [ExmtTdsCircularDate] [varchar](10) NULL, 
    [ExmtTdsEffectiveDate] [varchar](10) NULL, 
    [ExmtTdsIGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsCGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsSGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsUTGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsCessRt] [decimal](6, 2) NULL, ------ **** 
    [SupplyCategory] AS (case when [GstIGSTRt]<=(0.05) then 'Essential' when [GstIGSTRt]>=(0.05) AND [GstIGSTRt]<=(0.12) then 'Standard I' when [GstIGSTRt]>=(0.12) AND [GstIGSTRt]<=(0.18) then 'Standard II' else 'Luxury' end) PERSISTED NOT NULL, 
    [Code] [varchar](10) NULL, 
PRIMARY KEY CLUSTERED 
(
    [MasterId] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

GO 

SET ANSI_PADDING OFF 

這是表tblGlobalGSTRatesMasterII的結構:

CREATE TABLE [master].[tblGlobalGSTRatesMasterII] 
(
    [MasterId] [bigint] IDENTITY(1,1) NOT NULL, 
    [HSNSAC] [varchar](10) NULL, 
    [Description] [varchar](500) NULL, 
    [UnitofMeasurement] [varchar](30) NULL, 
    [GstIGSTRt] [decimal](6, 2) NULL, 
    [GstCGSTRt] [decimal](6, 2) NULL, 
    [GstSGSTRt] [decimal](6, 2) NULL, 
    [GstUTGSTRt] [decimal](6, 2) NULL, 
    [GstCessRt] [decimal](6, 2) NULL, 
    [ExmtCircularNumber] [varchar](20) NULL, 
    [ExmtCircularDate] [varchar](10) NULL, 
    [ExmtEffectiveDate] [varchar](10) NULL, 
    [ExmtGstIGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstCGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstSGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstUTGSTRt] [decimal](6, 2) NULL, 
    [ExmtGstCessRt] [decimal](6, 2) NULL, 
    [TdsIGSTRt] [decimal](6, 2) NULL, 
    [TdsCGSTRt] [decimal](6, 2) NULL, 
    [TdsSGSTRt] [decimal](6, 2) NULL, 
    [TdsUTGSTRt] [decimal](6, 2) NULL, 
    [TdsCessRt] [decimal](6, 2) NULL, 
    [ExmtTdsCircularNumber] [varchar](20) NULL, 
    [ExmtTdsCircularDate] [varchar](10) NULL, 
    [ExmtTdsEffectiveDate] [varchar](10) NULL, 
    [ExmtTdsIGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsCGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsSGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsUTGSTRt] [decimal](6, 2) NULL, 
    [ExmtTdsCessRt] [decimal](6, 2) NULL, 
PRIMARY KEY CLUSTERED 
(
    [MasterId] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

GO 

SET ANSI_PADDING OFF 
GO 
+1

花時間很好地格式化你的問題,並使用道具呃拼寫和語法(例如,請說出「please」而不是「請」,當提到你自己時使用大寫字母「I」,並以全停/句號結束句子),人們將更傾向於幫助你。如果你不會花時間提出一個好問題,那麼人們就不會花時間來回答它。 – Clonkex

回答

0

您可以使用此

SET IDENTITY_INSERT [master].[tblGlobalGSTRatesMasterII] ON 

INSERT INTO [master].[tblGlobalGSTRatesMasterII] 
(
[MasterId], 
    [HSNSAC], 
    [Description], 
    [UnitofMeasurement], 
    [GstIGSTRt], 
    [GstCGSTRt], 
    [GstSGSTRt], 
    [GstUTGSTRt], 
    [GstCessRt], 
    [ExmtCircularNumber], 
    [ExmtCircularDate], 
    [ExmtEffectiveDate], 
    [ExmtGstIGSTRt], 
    [ExmtGstCGSTRt], 
    [ExmtGstSGSTRt], 
    [ExmtGstUTGSTRt], 
    [ExmtGstCessRt], 
    [TdsIGSTRt], 
    [TdsCGSTRt], 
    [TdsSGSTRt], 
    [TdsUTGSTRt], 
    [TdsCessRt], 
    [ExmtTdsCircularNumber], 
    [ExmtTdsCircularDate], 
    [ExmtTdsEffectiveDate], 
    [ExmtTdsIGSTRt], 
    [ExmtTdsCGSTRt], 
    [ExmtTdsSGSTRt], 
    [ExmtTdsUTGSTRt], 
    [ExmtTdsCessRt] 
) 

SELECT TOP 1 
    [MasterId], 
    [HSNSAC], 
    [Description], 
    [UnitofMeasurement], 
    [GstIGSTRt], 
    [GstCGSTRt], 
    [GstSGSTRt], 
    [GstUTGSTRt], 
    [GstCessRt], 
    [ExmtCircularNumber], 
    [ExmtCircularDate], 
    [ExmtEffectiveDate], 
    [ExmtGstIGSTRt], 
    [ExmtGstCGSTRt], 
    [ExmtGstSGSTRt], 
    [ExmtGstUTGSTRt], 
    [ExmtGstCessRt], 
    [TdsIGSTRt], 
    [TdsCGSTRt], 
    [TdsSGSTRt], 
    [TdsUTGSTRt], 
    [TdsCessRt], 
    [ExmtTdsCircularNumber], 
    [ExmtTdsCircularDate], 
    [ExmtTdsEffectiveDate], 
    [ExmtTdsIGSTRt], 
    [ExmtTdsCGSTRt], 
    [ExmtTdsSGSTRt], 
    [ExmtTdsUTGSTRt], 
    [ExmtTdsCessRt] 
FROM [master].[tblGlobalGSTRatesMasterI] 
SET IDENTITY_INSERT [master].[tblGlobalGSTRatesMasterII] OFF 
相關問題