Problem!! Trying to create a table with various type fields....

  • Hi I have a table:

    Create table

    ( max_value nvarchar(50))

    Now I want to input all the max values within a particular column to this table.

    i.e insert into table

    select Max(column) from Table1

    my code runs it in a loop so it will put all max columns of a table into this field.

    My problem is I can have varying column types. i.e. Column with varchar, column with numeric, column with money.

    What can i assign the column Max_Value in my table to handle all of these different datatypes??

    The query can work, but produces an error when it gets to the money type columns

  • Maybe too simple, but did you try this:

    insert into table

    select Max(cast(column as Varchar)) from Table1

  • Hi thanks!!

    I solved with:

    cast(max(['

    +@Column_Name+ ']) as varchar) as Max_Value

    Thanks!

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

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