Change columntype in a view

  • Hi all,

    i have created a view to calculate with hours (numbers). Whole numbers (1 to 9) is no problem but when i have e.g. 6.5 and i want to multiply this by 60 i get an error in the view: Conversion failed when converting the varchar value '6.5' to data type int. I have tried it with 6,5 and tried using "CAST(beschikbaar * 60 AS float) as BES" and also Convert but i still get the error. How can i resolve this problem?? BTW beschikbaar is nvarchar(50).

    This is my full code:

    SELECT Mont, Datum, Feestdag, Ziek, Snipperuren, Start1, Stop1, Start2, Stop2, Pauze, VrijSDvan, VrijSDtot, Schoolvan, Schooltot, Gakdag, Diversen,

    [1e monteur], [2e monteur], [Zomer SD], [4-daagseweek], beschikbaar, AantalSD, Afd, CASE WHEN vrijsdtot IS NULL

    THEN 0 ELSE VrijSDtot - VrijSDvan END AS VrijSD, Stop1 - Start1 AS saldo, CAST(beschikbaar * 60 AS float) AS bes, Stop2 - Start2 AS saldo2, weekdag,

    datum2

    FROM dbo.TabelConversie

  • try changing just the offending columns with CAST or CONVERT, and not the whole formula:

    CAST(beschikbaar * 60 AS float)

    changes to

    CAST(beschikbaarAS float) * 60

    I think that will solve your problem.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks Lowell, so simple.:)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply