INSERT statement using variables

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: sm (sm_at_discussions.microsoft.com)
Date: 11/02/04


Date: Tue, 2 Nov 2004 00:04:06 -0800

Hi All,

Can anybody give me the syntax to insert a record into SQL server through VB
code using variables?

The following statement is failing!
sInsertQuery = "INSERT INTO TestTab (Col1, Col2, Col3, Col4) Values(" & _
                     str1 & "," & dt1 & "," & str2 & "," & str3 & ")"

where str1 = "col1"
dt1 = getdate()
str2 = "col2"
str3 = "col3"

Thanks



Relevant Pages

  • Re: Index View
    ... I also have Ent. ... Indexed views are supported by SQL Server 2000. ... can't use this for your query. ... GETDATE()" prohibits this view from being indexed. ...
    (microsoft.public.sqlserver.programming)
  • Re: How to initialice a default value for a column in a typed DataSet
    ... my approach has always been to create a DEFAULT in SQL Server and bind ... The DEFAULT can be an expression like GETDATE(). ... > save (the client app sees a "nothing" while the database has a datetime). ... >> I have a typed dataset that corresponds to a SQL Server database model. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: getdate() in UDF
    ... > But the same problem would exist if getdate() was replaced by an input ... that is data in the database and input parameters. ... Here noofyears is a computed column which tells us how long a person ... SQL Server must materialize the values. ...
    (microsoft.public.sqlserver.programming)
  • Re: Index View
    ... >>performance problem. ... I also have Ent. ... > GETDATE()" prohibits this view from being indexed. ... what indexes get used by SQL Server? ...
    (microsoft.public.sqlserver.programming)
  • Re: Clean checkdb & checkcatalog - why is "Attempt to repair any minor problems" kick
    ... The command has to run in single_user mode and the maintenance job is ... Microsoft SQL Server Storage Engine ... >> up by them)started failing. ... >> Integrity check should be running an DBCC CHECKDB, ...
    (microsoft.public.sqlserver.server)