sql - Stored Procedure consist Add column, Update data for that column, and Select all data from that table -
I have written a stored procedure as the following:
CREC SPSoNguoiThan @SNT IF is starting as int (choose column_name from INFORMATION_SCHEMA.column where table_name = 'nanavin' and 'column_name =' sonangei tan ')) optional table NhanVien ADD SoNguoiThan otherwise updated NhanVien SET NhanVien.SoNguoiThan = (SELECT Count (MaNguoiThan) NguoiThan WHERE MaNV = NhanVien.MaNV Group by NhanVien.MaNV) Select End * from NhanVien where SoNguoiThan & gt; Go to the end of @SNT
Then I get an error:
Server: message 207, level 16, state 1, process SpsOgui tan, line 12 invalid The column name 'Soungoethan'. Server: Message 207, Level 16, State 1, Process Spsogyi Tan, Line 15 Invalid column name 'Soungoethan'.
When the stored procedure is parsed during the called column, you receive an error.
Run the internal code line from the line because they run different batch (updates) because columns exist.
The only way around this is to use the dynamic SQL for the update and select so that it can not be understood until the executed time (do not make time yet).
However, this is something I really will not do: DDL and DML in the same bit of code
Comments
Post a Comment