Hi All.
I have an SQL statement like sqlStatement += " and C >="+Number1+" and C <= "+Number2+" "; this works fine with Numbers. How do I change it if Numbers were dates? thanks
You can use cast and convert as appropriate to convert everything to string. For example,
DECLARE @AnInteger INT = 10;
SELECT
'Some text data ' + CAST(@AnInteger AS VARCHAR(32)) + CONVERT(VARCHAR(20), GETDATE(), 101);
Alternatively, use the CONCAT function.
DECLARE @AnInteger INT = 10;
SELECT CONCAT(
'Some text data ' , @AnInteger , GETDATE()
);
There are some nuances - e.g., in the former, if any field is NULL, the result will be null unless you handle it using COALESCE or ISNULL, and in the latter, the date values will use a default formatting, unless you convert it to your desired format.