自动生成基于日期的代码

时间:2018-04-12 07:08:42

标签: sql-server

我想问一下如何在production_date列上生成批处理代码?

我的查询:

SELECT  receiving_detail.con_id,   
         receiving_detail.ITEM_ID,      
         receiving_detail.TRANSACTION_QTY,   
         receiving_detail.UNIT_COST,  
         receiving_detail.UOM_ID,   
            item_master_list.item_code,  
            receiving_detail.po_item_id,
            receiving_detail.production_date,
            receiving_detail.expiration_date,
            receiving_detail.batch_code
    FROM receiving_detail   left join item_master_list on item_master_list.id=receiving_detail.item_id

预期产出:

con_id  ITEM_ID item_code   production_date expiration_date batch_code
413797  366     508246      2018-01-17       2018-07-17     180117
415012  108101  512761      2018-01-17       2019-01-17     180117
339027  27      301283      2017-09-19       2018-01-17     180117

1 个答案:

答案 0 :(得分:0)

SELECT  receiving_detail.con_id,   
         receiving_detail.ITEM_ID,      
         receiving_detail.TRANSACTION_QTY,   
         receiving_detail.UNIT_COST,  
         receiving_detail.UOM_ID,   
            item_master_list.item_code,  
            receiving_detail.po_item_id,
            receiving_detail.production_date,
            receiving_detail.expiration_date,
            convert(varchar, receiving_detail.production_date, 12) AS batch_code

    FROM receiving_detail   left join item_master_list on item_ma