Update does not have a from
clause (see update syntax on SQLite site) and also see sqldf FAQ #8 for the commonly made error of updating the table in SQLite but then not returning the table to R.
R language sqldf package update table not working
题
i exported some data from a csv file into R. i am using sqldf package to udpate data. My below query runs. i can provide my csv file but i dont know how to attach files here :(
> sqldf("select * from
+ (
+
+ select Disposition as dummy_disposition, case Disposition
+ when 'Disposition' then 'UNKNOWN'
+ when 'Donate' then 'EOL'
+ when 'Resale' then 'EOL'
+ when 'Harvest' then 'EOL'
+ when 'IntelSpinOff' then 'EOL'
+ when 'Scrap' then 'EOL'
+ when 'BufferFeedForward' then 'ACTIVE'
+ when 'FB' then 'UNKNOWN'
+ when 'Unknown' then 'UNKOWN'
+ when 'HarvestResale' then 'EOL'
+ when 'ReturnToSupplier' then 'EOL'
+ when 'IcapResale' then 'EOL'
+ when 'NonEmsManaged' then 'EOL'
+ when 'BufferEOL' then 'EOL'
+ when 'ResaleScrap' then 'EOL'
+ when 'ST' then 'UNKNOWN'
+ when 'AS' then 'UNKNOWN'
+ else null end as new_status,
+
+ * from a where FloorStatus is null and disposition is not null
+
+
+ ) as table1
+ where new_status is null")
[1] dummy_disposition new_status Ueid Date EndDate
[6] Site CFD Type ScheduleId EventType
[11] FloorStatus EntityCode Ceid Process Supplier
[16] FA MfgType Disposition Comments extra1
[21] extra2 extra3
<0 rows> (or 0-length row.names)
but when i run below query it doesnt run :( It is interesting because except update table part rest of the query is part of the above query.
> sqldf("update a set FloorStatus = case Disposition
+ when 'Disposition' then 'UNKNOWN'
+ when 'Donate' then 'EOL'
+ when 'Resale' then 'EOL'
+ when 'Harvest' then 'EOL'
+ when 'IntelSpinOff' then 'EOL'
+ when 'Scrap' then 'EOL'
+ when 'BufferFeedForward' then 'ACTIVE'
+ when 'FB' then 'UNKNOWN'
+ when 'Unknown' then 'UNKNOWN'
+ when 'HarvestResale' then 'EOL'
+ when 'ReturnToSupplier' then 'EOL'
+ when 'IcapResale' then 'EOL'
+ when 'NonEmsManaged' then 'EOL'
+ when 'BufferEOL' then 'EOL'
+ when 'ResaleScrap' then 'EOL'
+ when 'ST' then 'UNKNOWN'
+ when 'AS' then 'UNKNOWN'
+ else null end
+ from a where FloorStatus is null and disposition is not null")
Error in sqliteExecStatement(con, statement, bind.data) :
RS-DBI driver: (error in statement: near "from": syntax error)
what is wrong with my update table command? when i run my code in sql development studio it runs fine...but i would prefer if code runs in R
UPDATE:
what changes do i need to make to the below code????
declare @outputs table
([day] datetime,
floorstatus varchar,
quantity int)
declare @Date datetime;
DECLARE dates_cursor CURSOR FOR
SELECT clndr_dt from epsd.dbo.t_calendar
where clndr_dt between '2008-01-01' and '2013-08-13'
order by clndr_dt
OPEN dates_cursor
FETCH NEXT from dates_cursor INTO @Date
WHILE @@FETCH_STATUS = 0
BEGIN
insert @outputs
select @Date as [Day], floorstatus, count(floorstatus) as quantity from Graph_data
where @Date between [Date] and EndDate
group by floorstatus
FETCH NEXT from dates_cursor INTO @Date
END
CLOSE dates_cursor
DEALLOCATE dates_cursor
select * from @outputs
解决方案
不隶属于 StackOverflow