Below is a list of numeric styles supported by the CONVERT() function in SQL Server. These are the styles that can be used as the third argument to indicate how the input value is formatted.
t-sql
Fix Error Msg 8116 “Argument data type datetime2 is invalid for argument 1 of isdate function” in SQL Server
If you’re getting an error that reads Argument data type datetime2 is invalid for argument 1 of isdate function, it’s because you’re passing a datetime2 value to the ISDATE() function, but this function doesn’t work with datetime2 values.
To fix this issue, either pass a valid date type or use the work around below to provide similar functionality that works with datetime2 values.
How TRY_PARSE() Works in SQL Server
In SQL Server, the TRY_PARSE() function returns the result of an expression, translated to the requested data type, or NULL if the conversion fails.
Basically, it works the same as the PARSE() function, except that it returns NULL instead of an error if the cast fails.
Both functions are intended for converting string values to either date/time or number types.
How PARSE() Works in SQL Server
In SQL Server, the PARSE() function returns the result of an expression, translated to the requested data type.
Basically, it enables us to parse a string expression to the specified data type. It’s intended for converting string values to either date/time or number types.
The PARSE() function can be handy when attempting to convert with CAST() or CONVERT() fails. The PARSE() function is able to parse the expression, and this may result in certain values being converted that wouldn’t normally be able to be converted.
How to Convert Dates in SQL Server
When it comes to converting date and time values in SQL Server, things can get a little complex. But in this article I hope to demystify this topic for anyone who’s confused when it comes to making conversions between dates and other data types, as well as changing the format of date/time values, and other considerations.
Let’s jump straight in.
Fix “NEXT VALUE FOR function does not support the PARTITION BY clause.” (Error Msg 11716) in SQL Server
If you’re getting an error that reads “NEXT VALUE FOR function does not support the PARTITION BY clause” in SQL Server, it’s probably because you’re trying to use the PARTITION BY sub clause in an OVER clause when using NEXT VALUE FOR to increment a sequence object.
In other words, the NEXT VALUE FOR function does not support the PARTITION BY sub clause of the OVER clause.
To fix this issue, either remove the PARTITION BY clause or change the statement to use another method for partitioning the results.
Create a Sequence using the Default Values in SQL Server
When creating a sequence object in SQL Server, it’s common to set various properties such as the start value, the increment, and even things like the maximum and minimum values for the sequence. But it is also possible to create a sequence without setting any of these properties.
Get All Parameters from a SQL Server Database (T-SQL)
In SQL Server we can query the sys.parameters system catalog view to return all parameters that belong to user-defined objects.
For system objects, we can query the sys.system_parameters view. We can alternatively query the sys.all_parameters system catalog view to return all parameters that belong to either user-defined or system objects.
How to Create a Synonym in SQL Server (T-SQL)
In SQL Server we can create synonyms, which allow us to provide an alternative name for a database object. Once created, we can reference the synonym instead of the object itself.
Return All DEFAULT Constraints in a SQL Server Database (T-SQL)
In SQL Server, we can query the sys.default_constraints system catalog view to return a list of DEFAULT constraints in the current database.