0

我想在下拉列表中将产品和日期绑定在一起

这是sql查询

Select P.Id , M.ProductId as ProId , P.Name + ',+'M.[Date] as Name 
from ProductMaster as P INNER JOIN PlanMaster as M on P.Id= M.ProductId  
where M.IsDelete = 'False' order by  M.ProductId ASC

如果date不是datetime格式,这有效

我得到的错误是

从字符串转换日期时间时转换失败。

4

2 回答 2

1

您必须先转换M.Date为,varchar然后才能将其与P.Name

如果你正在使用SQL-Server,试试这个

Select P.Id , M.ProductId as ProId ,
       P.Name + ','+ Cast(M.[Date] as varchar) as Name 
....

编辑:如果你只想要日期部分

Select P.Id , M.ProductId as ProId ,
           P.Name + ','+ CONVERT(VARCHAR(10),M.[Date],111) as Name 
    ....
于 2012-07-18T11:43:04.937 回答
0
Select M.CODE as Id , M.ProductId as ProId ,  M.Code + ' ,' +P.Name + ' , '+CONVERT(VARCHAR(10),M.[Date],105)  as Name from ProductMaster as P INNER JOIN PlanMaster as M on P.Id= M.ProductId  where M.IsDelete = 'False' order by  M.ProductId ASC

基本上 :CONVERT(VARCHAR(10),M.[Date],105)

因为我想拥有它dd/mm/yyyy

于 2012-07-19T06:09:15.113 回答