I'm writing a SQL script to register components in a database. One of these requires DateTime (from last year) to be inserted as one of the values into a table, like this:
INSERT INTO ComponentTable (ComponentId, Setting, [Value]) VALUES ('id', 'StartDate', ... )
The C# I had previously been using to insert the value was DateTime.Today.AddDays(-365).ToString() (before switching to a database).
Is there a way of adding the same thing into the SQL script above?
Thanks
ToString()- that's just asking for problems, and strongly suggests that you're also likely to be introducing SQL injection holes (and i18n/l10n errors); dates should be sent as datetime parameters, not forced into strings; let me know if you need help with that - this is a VERY IMPORTANT thing, not just a nitCAST(DATEADD(YEAR, -1, GETDATE()) AS DATE)