• luissantos (5/5/2015)


    Hello comunity

    I found a code snippet that use the curious following sintax on the creation of View:

    CREATE VIEW [dbo].[vw_EvenValues]

    AS

    SELECT [TestColumn]

    FROM [dbo].[TestTable]

    WHERE [TestColumn] % 2 = 1

    I don´t understand this:

    WHERE [TestColumn] [highlight=#ffff11]% 2 [/highlight]= 1

    IF [TestColumn] on the Select is varchar, then error occurs and say:

    "Conversion failed when converting for the varchar value 'A001' to data type int"

    Someone could explain what thas it´s mean.

    Best regards,

    Luis Santos

    Looks to me that the name of the view is wrong, CREATE VIEW [dbo].[vw_EvenValues]. The view will return ODD values, not even.

    For even values in TestColumn the where clause should be this:

    WHERE TestColumn % 2 = 0