How to use variables in a sql query using VBA

How to use variables in a sql query using VBA

Post by a.. » Tue, 17 Mar 1998 04:00:00



How do I perform a sql query using variables?, something like

select * from table1 where field1=VARIABLE

I supose, but I cant get it right.

Thank You

 
 
 

How to use variables in a sql query using VBA

Post by a.. » Tue, 17 Mar 1998 04:00:00


Found it out myself......should be
select * from table1 where field1="& VARIABLE &"

Quote:>How do I perform a sql query using variables?, something like

>select * from table1 where field1=VARIABLE

>I supose, but I cant get it right.

>Thank You


 
 
 

How to use variables in a sql query using VBA

Post by Lee J. Wein » Tue, 17 Mar 1998 04:00:00



>How do I perform a sql query using variables?, something like

>select * from table1 where field1=VARIABLE

>I supose, but I cant get it right.

"select * from table1 where field1 = '" & variable & "'"        if it's a
string variable.

"select * from table1 where field1 = #" & variable & "#"        if it's a date
variable.

"select * from table1 where field1 = " & variable               if it's a
numeric variable.

Lee Weiner
weiner AT fuse DOT net

 
 
 

How to use variables in a sql query using VBA

Post by David Costello » Thu, 19 Mar 1998 04:00:00


Quote:>select * from table1 where field1=VARIABLE

' For Strings
UserChoise$ = Text1.Text

Data1.recordsource = "SELECT * FROM [Table] WHERE [Field] = ' " &
UserChoice$ & " ' "

'For Numeric

UserChoise% = CInt(Text1.Text)

Data1.recordsource = "SELECT * FROM [Table] WHERE [Field] = " & UserChoice%

Hope this helps
David.....

 
 
 

1. DTS: Using Global Variables in a DT SQL Query

I am developing a package that will utilitize VB talking to a DTS Package.
In the package I would like to use GlobalVariables to select subsets of the
data.  Is there a way in the SQL portion of the DTS Workflow to use the
value from the global Variable.

I have not found any documentation about how this might be accomplished.

Any suggestions would be greatly appreciated,

John

2. VB via ODBC to Sybase

3. Help:SQL Query using a Date/time variable

4. : identifying runaway DB clients

5. Help with SQL query using LIKE and variable field

6. Parsing in Trans-SQL -- Need Help

7. more about jobs

8. PLEASE HELP: Using Variables within SQL Queries

9. Using variables in SQL queries

10. SQL query using a variable

11. Using a variable in a SQL Query

12. Find using sql query with variable having an apostrophe