Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

SQL + Variables

 
   Database Help (Home) -> Visual Basic RSS
Next:  A single row has #DELETED across it. How did that..  
Author Message
Kevin Robinson

External


Since: Oct 12, 2004
Posts: 5



(Msg. 1) Posted: Tue Feb 15, 2005 1:40 am
Post subject: SQL + Variables
Archived from groups: comp>lang>basic>visual>database (more info?)

How do you include a variable in a select statement using VB6/Access.

I want to do something like this :
SELECT * from A where A.field = variable


Thanks

Kevin

 >> Stay informed about: SQL + Variables 
Back to top
Login to vote
John Blessing2

External


Since: May 11, 2004
Posts: 3



(Msg. 2) Posted: Tue Feb 15, 2005 5:40 am
Post subject: Re: SQL + Variables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Kevin Robinson" <k.s.robinson DeleteThis @btinternet.com> wrote in message
news:cus28v$1l6$1@titan.btinternet.com...
 > How do you include a variable in a select statement using VB6/Access.
 >
 > I want to do something like this :
 > SELECT * from A where A.field = variable
 >
 >
 > Thanks
 >
 > Kevin
 >

dim strVar as string
dim lVar as long

strVar = "Hello"
lVar = 10

strql = "select col1, col2 from A where a.col1 = '" & strVar & "' and
a.col2= " & cstr(lvar)

Note:

'" is single quote followed by double quote
"' is double quote followed by single quote

so that a ?strSql would give you

select col1,col2 from A where a.col1='Hello' and a.col2=10

<pedant>Database tables have columns, not fields. A field more properly
refers to an input area on a user interface</pedant>

Including the table name with the column name is not strictly necessary when
you are selecting from one table only.

Also, never use select *. One day someone will add a blob column to your
database and you will be retrieving massive data amounts when you don't need
it

--
John Blessing

<a style='text-decoration: underline;' href="http://www.LbeHelpdesk.com" target="_blank">http://www.LbeHelpdesk.com</a> - Help Desk software priced to suit all
businesses
<a style='text-decoration: underline;' href="http://www.room-booking-software.com" target="_blank">http://www.room-booking-software.com</a> - Schedule rooms & equipment bookings
for your meeting/class over the web.
<a style='text-decoration: underline;' href="http://www.lbetoolbox.com" target="_blank">http://www.lbetoolbox.com</a> - Remove Duplicates from MS Outlook<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: SQL + Variables 
Back to top
Login to vote
Kevin Robinson

External


Since: Oct 12, 2004
Posts: 5



(Msg. 3) Posted: Tue Feb 15, 2005 2:40 pm
Post subject: Re: SQL + Variables [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thanks for this info.It helped me solve a problem.


Regards

Kevin

"John Blessing" <newsgroup.DeleteThis@LbeHelpdesk.com> wrote in message
news:37dss1F56k0irU1@individual.net...
 >
 > "Kevin Robinson" <k.s.robinson.DeleteThis@btinternet.com> wrote in message
 > news:cus28v$1l6$1@titan.btinternet.com...
  > > How do you include a variable in a select statement using VB6/Access.
  > >
  > > I want to do something like this :
  > > SELECT * from A where A.field = variable
  > >
  > >
  > > Thanks
  > >
  > > Kevin
  > >
 >
 > dim strVar as string
 > dim lVar as long
 >
 > strVar = "Hello"
 > lVar = 10
 >
 > strql = "select col1, col2 from A where a.col1 = '" & strVar & "' and
 > a.col2= " & cstr(lvar)
 >
 > Note:
 >
 > '" is single quote followed by double quote
 > "' is double quote followed by single quote
 >
 > so that a ?strSql would give you
 >
 > select col1,col2 from A where a.col1='Hello' and a.col2=10
 >
 > <pedant>Database tables have columns, not fields. A field more properly
 > refers to an input area on a user interface</pedant>
 >
 > Including the table name with the column name is not strictly necessary
when
 > you are selecting from one table only.
 >
 > Also, never use select *. One day someone will add a blob column to your
 > database and you will be retrieving massive data amounts when you don't
need
 > it
 >
 > --
 > John Blessing
 >
 > <a style='text-decoration: underline;' href="http://www.LbeHelpdesk.com" target="_blank">http://www.LbeHelpdesk.com</a> - Help Desk software priced to suit all
 > businesses
 > <a style='text-decoration: underline;' href="http://www.room-booking-software.com" target="_blank">http://www.room-booking-software.com</a> - Schedule rooms & equipment bookings
 > for your meeting/class over the web.
 > <a style='text-decoration: underline;' href="http://www.lbetoolbox.com" target="_blank">http://www.lbetoolbox.com</a> - Remove Duplicates from MS Outlook
 >
 ><!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: SQL + Variables 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
sql query returns in wrong format - Hi, Hope someone can help me with this. I have MS SQL 2000 database where i have Table "PriceList" and there a column "Pricemk" wich is data type "money". All data in this column is in form "10001,35". So why when...

arrays - is there a way to concatenate the contents of an array (looping through the array) and storing each item in a comma delimited string? Thanks!

DataReport PageBreak - Hi everyone, I would like to know how to force pagebreak in a datareport for example after 5 records printed. Thank you all

Possible Use of a Cursor - I have a complex query that I hope I can explain it well enough for everyone to understand. I have a table that contains information for work instructions. Contained in the table are "MACHINE_PROC" these are groupings of machining processes....

Scroll Bars - Is there a way to find the size of scrollbars on a system using Visual Basic 6.0? I know how to look and change them on the display properties, but I don't know how to access that information from within Visual Basic.
   Database Help (Home) -> Visual Basic All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]