SQL INSERT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scrappy

    SQL INSERT

    I have a table named expense_report. It has over 100 columns in it. Most
    of the columns are of type "money(8)". I have a form on my website that I
    created using Frontpage and a custom query. I hade to convert most columns
    from money to varchar to get the format that I was looking for on the
    display page. i.e. $1,265.33. My ultimate goal is to have an e-mail sent
    to someone when ever there is a database submisssion. I am following some
    directions that I found on the Internet. I have the form and then I am
    creating an ASP email handeler page. This calls for an INSERT INTO
    statement. I set is up as follows: INSERT INTO expense_report (break_mon,
    break_tue) VALUES ('::break_mon:: ', '::break_tue::' ) When I verify the
    query, it tells me that I can not INSERT varchar into a money column. Do I
    have to convert the input to money and then convert to output back to
    varchar? How is this done. I am familiar with cast and convert functions,
    but only in a SELECT statement. Any help would be appreciated. Thanks!

    Darren
    MCP


  • Erland Sommarskog

    #2
    Re: SQL INSERT

    Scrappy (celtics@lan-specialist.com) writes:[color=blue]
    > I have a table named expense_report. It has over 100 columns in it.
    > Most of the columns are of type "money(8)". I have a form on my website
    > that I created using Frontpage and a custom query. I hade to convert
    > most columns from money to varchar to get the format that I was
    > looking for on the display page. i.e. $1,265.33.[/color]

    It is usually better to formatting client-side, as you there can
    use regional settings, so that users see for instance dates in a
    format they like.
    [color=blue]
    >This calls for an INSERT INTO
    > statement. I set is up as follows: INSERT INTO expense_report
    > (break_mon, break_tue) VALUES ('::break_mon:: ', '::break_tue::' )
    > When I verify the query, it tells me that I can not INSERT varchar into a
    > money column. Do I have to convert the input to money and then convert to
    > output back to varchar? How is this done. I am familiar with cast and
    > convert functions, but only in a SELECT statement.[/color]

    INSERT is no different:

    create table #x (m money NOT NULL)
    go
    insert #x values (convert(money, '$1,265.33'))
    go
    select * from #x



    --
    Erland Sommarskog, SQL Server MVP, sommar@algonet. se

    Books Online for SQL Server SP3 at
    SQL Server 2025 redefines what's possible for enterprise data. With developer-first features and integration with analytics and AI models, SQL Server 2025 accelerates AI innovation using the data you already have.

    Comment

    Working...