SQL+语法请教
declare @ls_temp_tablename char(32)
declare @ls_print varchar(100),@ls_print_z varchar(100),@ls_print_key varchar(100)
DECLARE authors_cursor CURSOR FOR
SELECT DISTINCT tablename
FROM r_temptable
WHERE (isbill = 1) ----
OPEN authors_cursor
FETCH NEXT FROM authors_cursor INTO @ls_temp_tablename
WHILE @@FETCH_STATUS = 0
BEGIN
set @ls_print ='delete from '+ rtrim(@ls_temp_tablename) where billdate<'2013-01-01'
set @ls_print_z ='delete from '+ rtrim(@ls_temp_tablename)+'_z' where billid in set @ls_print_key ='UPDATE as_tablekeys SET maxkey = SELECT isnull(MAX(billID), 0) + 1 FROM rtrim(@ls_temp_tablename) WHERE tablename =rtrim(@ls_temp_tablename) '
EXEC (@ls_print)
EXEC (@ls_print_z)
exec (@ls_print_key)
FETCH NEXT FROM authors_cursor INTO @ls_temp_tablename
END
CLOSE authors_cursor
DEALLOCATE authors_cursor
请问里面的应该怎么使用+号,''号?
set @ls_print ='delete from '+ rtrim(@ls_temp_tablename) where billdate<'2013-01-01'
set @ls_print_z ='delete from '+ rtrim(@ls_temp_tablename)+'_z' where billid in set @ls_print_key ='UPDATE as_tablekeys SET maxkey = SELECT isnull(MAX(billID), 0) + 1 FROM rtrim(@ls_temp_tablename) WHERE tablename =rtrim(@ls_temp_tablename) '
------解决方案--------------------set @ls_print ='delete from '+ rtrim(@ls_temp_tablename)+' where billdate<''2013-01-01'''
------解决方案--------------------你这个_z是表名的一部分吗?还有where billid in这里只有半句啊
set @ls_print_z ='delete from '+ rtrim(@ls_temp_tablename)+'_z where billid in '
set @ls_print_key ='UPDATE as_tablekeys SET maxkey = (SELECT isnull(MAX(billID), 0) + 1 FROM
'+rtrim(@ls_temp_tablename)+' WHERE tablename ='''+rtrim(@ls_temp_tablename)+''')'