我想和
做同样的事 /*This code works fine in mysql Android*/
SELECT id, client, num, fs, tus,
convert(datetime, fs, 103) AS Fecha,
SUBSTRING( fs, 9, 2) AS day,
SUBSTRING( fs, 6, 2) AS month,
SUBSTRING( fs, 1, 4) AS year
FROM table
WHERE fs <> 'NULL'
AND mes = '07'
AND anio = '2014'
AND dia = '11'
ORDER BY dia ASC;
/*But in SQL is different a cause of datetime and here is where i cant make it work*/
SELECT
convert(datetime, fs, 103) AS fs,
datePart(mm, convert(datetime, fs, 103)) AS month ,
datePart(yyyy, convert(datetime, fs, 103)) AS year,
datePart(dd, convert(datetime, fs, 103) AS day)
FROM table
WHERE day <> 'NULL'
我不知道如何将fs,月,年和日作为表来操纵它们
答案 0 :(得分:0)
如果您想将字段与NULL
进行比较,只需使用完整字段:
WHERE fecha_servicio is not null;
如果该值可以是'NULL'
,那么您可以尝试:
WHERE fecha_servicio <> 'NULL';
但是,SQL引擎可能会在进行过滤之前评估select
,在这种情况下,您将在转换时收到错误。如果您使用的是SQL Server 2012+,请使用try_convert()
代替convert()
。