动态sql语句我们经常会用的到,下面为您介绍的是使用动态sql语句自定义列名的实现方法,如果您之前遇到过类似的问题,不妨一看。
- CREATE PROCEDURE POQUERY1
- (
- @SupplyID varchar(30) --参数
- )
- AS
- DECLARE @no nvarchar(100)
- DECLARE @seq nvarchar(100)
- DECLARE @ordq nvarchar(100)
- DECLARE @rdat nvarchar(100)
- DECLARE @pman nvarchar(100)
- DECLARE @pno nvarchar(100)
- DECLARE @cur nvarchar(100)
- DECLARE @opd1 nvarchar(100)
- DECLARE @pterm nvarchar(100)
- DECLARE @sql nvarchar(600)
- select @no=xfldd_from from xfld_D where xfldd_to='订购单号'
- select @seq=xfldd_from from xfld_D where xfldd_to='序号'
- select @ordq=xfldd_from from xfld_D where xfldd_to='订购数量'
- select @rdat=xfldd_from from xfld_D where xfldd_to='预定交期'
- select @pman=xfldd_from from xfld_D where xfldd_to='采购员'
- select @pno=xfldd_from from xfld_D where xfldd_to='件号'
- select @cur=xfldd_from from xfld_D where xfldd_to='币别'
- select @opd1=xfldd_from from xfld_D where xfldd_to='开立日期'
- select @pterm=xfldd_from from xfld_D where xfldd_to='付款条件'
- select @sql='SELECT
- PO_H.poh_no as ' + @no + ',
- PO_D.pod_seq as ' + @seq + ',
- PO_D.pod_ordq as ' + @ordq + ',
- PO_D.pod_rdat as ' + @rdat + ',
- PO_H.poh_pman as ' + @pman + ',
- PO_D.pod_pno as ' + @pno + ',
- PO_H.poh_cur as ' + @cur + ',
- PO_H.poh_opd1 as ' + @opd1 + ',
- PO_H.poh_pterm as ' + @pterm + '
- FROM
- PO_H,
- PO_D
- where
- PO_H.poh_vend=' + @SupplyID + '
- AND
- PO_D.pod_no=PO_H.poh_no'
- exec(@sql)
- GO
以上就是使用动态sql语句自定义列名的实现方法介绍。