Results 1 to 4 of 4

Thread: Implicit cast is forbidden

  1. #1
    Join Date
    Apr 2006
    Location
    Paris
    Posts
    7

    Implicit cast is forbidden

    Hi,
    I have noticed that implicit casts are allowed according to the actual data in a column.
    Here is an example:

    Code:
    SELECT * FROM MyTable WHERE MyColumn = 3897
    MyColumn is defined as nvarchar(15) not null in the database schema.

    This query will work only if there are no record in MyTable for which MyColumn has an alphanumerical value. Otherwise it will raise an error:

    Serveur : Msg 245, Niveau 16, État 1, Ligne 1
    Syntax error converting the nvarchar value 'C061' to a column of data type int.


    Of course, the following query is always successful:

    Code:
    SELECT * FROM MyTable WHERE MyColumn = '3897'

    Am I correct?


    Thanks a lot.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    You are right.

  3. #3
    Join Date
    Apr 2006
    Posts
    30
    MSDN Cast and Convert shows what can and cannot be converted and discusses implicit conversions.

  4. #4
    Join Date
    Apr 2006
    Location
    Paris
    Posts
    7
    Thanks a lot for your answers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •