テーブルに存在する場合は、列を更新する動的クエリを作成しています。更新クエリが実行されているときにエラーが発生します。 「varchar型の値を変換するアップデート製品はProductSellingPrice =((単価* [GSTRATEの%]を設定すると、変換が失敗した動的クエリが目的の結果を提供していません
- :手順を以下に示し
Create Procedure spr_UpdateColumnWithTotalPrice @id int as begin if not exists ( Select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'Product' and COLUMN_NAME = 'ProductSellingPrice' ) Begin Declare @SellingPrice varchar(max) Set @SellingPrice = 'Alter table Product add ProductSellingPrice int' Exec(@SellingPrice) Print 'Table altered' End Else Begin Set @SellingPrice = 'Update Product set ProductSellingPrice = ((UnitPrice * [GSTRATE%]/100) + UnitPrice) where ProductID = @id' Exec(@SellingPrice) Print 'Table updated' End
エンド
私は、次の結果を取得しています/ 100)+ UnitPrice)ProductID = @id 'をデータ型intに設定します。
助けてくださいと感謝事前に
あなたが投稿した正確なクエリは、あなたが得ていると言うエラーを生成しません。 –