Query related to length in CAST and Output clause

Salil Singh 40 Reputation points
2025-04-22T18:21:46.98+00:00

Hi Team,

Could you please reply to below queries -

  1. Using CAST, I need to convert BigInt and Datetime2 values to Varchar. How could I be sure on the length that I need to use (in CAST) to convert these values to Varchar.
  2. I am using Update statement with Output clause, in Output clause values, I am unable to use a user defined function as it is erroring out, could you let me know how to use a user defined function in Output clause (with Update).

Please let me know if more clarification is needed in any of above points.

Thanks,

Salil

SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
177 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Olaf Helper 46,636 Reputation points
    2025-04-24T06:20:32.56+00:00

    How could I be sure on the length that I need to use (in CAST) to convert these values to Varchar.

    Lookup the use data size per data type and you know the length for the VARCHAR type, see

    https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.