我的数据库中有很多表,我正在使用以下代码收集计算值,并希望将这些值插入到其他表中。我正在使用 SELECT INTO 方法,但数据库告诉我“关键字 INTO 行附近的语法不正确......”。我相信我缺少一些东西,但不确定在哪里。代码看起来不错。这是我的代码。任何帮助,将不胜感激。
SELECT (second.[cdate]=@enddate) AS 'Date', first.[machine_no] AS 'No',
tbl_machines.[manufacturer] As 'Manufacturer',
tbl_machines.[type] As 'Machine Type',tbl_machines.[game_name] AS 'Game Name',
tbl_machines.[accounting_denomination] AS 'Denom',
(second.[turnover])-(first.[turnover]) AS 'Turnover',
(second.[total win])-(first.[total win]) AS 'Total win',
(second.[games played])-(first.[games played]) AS 'Games Played',
(second.[Bill in])-(first.[Bill in]) AS 'Bill In',
(second.[credit in])-(first.[credit in]) AS 'Credit IN',
(second.[cancel credit])-(first.[cancel credit]) AS 'Cancel Credit',
tbl_rate.[euro] AS 'euro rate',
tbl_rate.[dollar] AS 'dollar rate'
INTO tbl_daily
FROM tbl.meter first,tbl.machines,tbl_rate
INNER JOIN tbl_meter second ON first.[Machine_No] = second.[Machine_No]
AND
tbl_machines.[local_no]=first.[machine_no]
WHERE first.[cDate] = @StartDate
AND second.[cDate] = @EndDate
AND tbl_rate.[cdate]=@enddate;
好的,我使用了 INSERT INTO 语法,一切顺利,但现在我遇到了日期时间问题。当我使用以下 sql 命令时,出现错误并显示“无法将数据类型位转换为日期时间”我尝试了 Martin 的 cast 方法,但它是相同的。
我的代码是
INSERT INTO tbl_daily SELECT tbl_machines.[ID] AS 'ID', (second.[cdate]=@enddate) AS 'CDate', first.[machine_no] AS 'No',
tbl_machines.[manufacturer] As 'Manufacturer',
tbl_machines.[type] As 'MachineType',
tbl_machines.[game_name] AS 'GameName',
tbl_machines.[accounting_denomination] AS 'Denom',
(second.[turnover]-first.[turnover]) AS 'Turnover',
(second.[total win]-first.[total win]) AS 'Totalwin',
(second.[games played]-first.[games played]) AS 'GamesPlayed',
(second.[credit in]-first.[credit in]) AS 'CreditIN',
(second.[Bill in]-first.[Bill in]) AS 'BillIn',
(second.[cancel credit]-first.[cancel credit]) AS 'CancelCredit',
tbl_rate.[euro] AS 'eurorate',
tbl_rate.[dollar] AS 'dollarrate'
FROM tbl_meter first,tbl_machines,tbl_rate
INNER JOIN tbl_meter second ON first.[Machine_No] = second.[Machine_No] AND tbl_machines.[local_no]=first.[machine_no]
WHERE first.[cDate] = @StartDate AND second.[cDate] = @EndDate AND tbl_rate.[cdate]=@enddate;