https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql

Conversion failed when converting the varchar value ' ' to data type int.

存储过程,有一个传递进来的参数是int类型的

在存储过程中,进行字符串拼接的话,需要把int手动转换成nvrchar

可以使用Cast或者Convert函数

SELECT 9.5 AS Original,
CAST(9.5 AS INT) AS [int],
CAST(9.5 AS DECIMAL(6, 4)) AS [decimal];
SELECT 9.5 AS Original,
CONVERT(INT, 9.5) AS [int],
CONVERT(DECIMAL(6, 4), 9.5) AS [decimal];

Original int decimal
9.5         9      9.5000

Convert String to DateTime

https://stackoverflow.com/questions/1135746/sql-server-convert-string-to-datetime

SELECT CONVERT(datetime, '2018/01/04 11:22:01', 120)

第三个参数,120是style,ODBC canonical,yyyy-mm-dd hh:mi:ss(24h) 。

SELECT CONVERT(datetime, '2018-01-04 11:22:01', 110)

第三个参数,110是style,USA,10 = mm-dd-yy,110 = mm-dd-yyyy

Date and Time styles

For a date or time data type expression, style can have one of the values shown in the following table. Other values are processed as 0.

Beginning with SQL Server 2012 (11.x), the only styles supported, when converting from date and time types to datetimeoffset, are 0 or 1.

All other conversion styles return error 9809.

 102ANSI2 = yy.mm.dd
102 = yyyy.mm.dd

23 yyyy-mm-dd

05-28 21:51