×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Variable value in query

Variable value in query

Variable value in query

(OP)
Sir I have these codes

db1='xyz'
file_name='E:\HOURLY\at20\20190901_1159'

		if m.con1>0
		TEXT TO cmd noshow
			backup database <<db1>> to disk='<<file_name\db1..bak>>'
		endtext
			
			if sqlexec(m.con1,cmd)<0
			aerror(laerror)
			messagebox(laerror[1,2])
				return.f.
		ENDIF 


It says:
Connectivity error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '&'.

Please help me to sort out the error message

RE: Variable value in query

Look at cmd in the debugger:

CODE

db1='xyz'
file_name='E:\HOURLY\at20\20190901_1159'
TEXT TO cmd noshow
  backup database <<db1>> to disk='<<file_name\db1..bak>>'
ENDTEXT

set step on 

If you want textmerge functionality in TEXT TO, you have to add the option TEXTMERGE:

CODE

TEXT TO cmd noshow TEXTMERGE 

Also mixing macro substitution and textmerging doesn't work. As the error message mentions a "&" sign, I assume you're doing that, though you don't post that. Here's a demo of trying to mix textmerging and macro substitution:

CODE

lcText ="xyz"
Clear


Text to lcTest noshow TEXTMERGE
<<"This is &lcText.">>
EndText
? lcTest

Text to lcTest noshow TEXTMERGE
This is <<&lcText.>>
EndText
? lcTest

Text to lcTest noshow TEXTMERGE
This is <<lcText>>
EndText
? lcTest 

The expression <<file_name\db1..bak>> will not work, neither exctly like that, as it combines several variable names in one string, nor with substition <<&file_name\&db1..bak>>, what you need is <<file_name>>\<<db1>>.bak

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Variable value in query

Fro a simple SQL command like this, you might prefer to do:

CODE -->

cmd = [backup database ] + db1 + [ to disk =' ] + file_name + [\db1..bak'] 

Often, a TEXT / ENDTEXT construction is useful when building complex SQL commands, but if you unsure how to do it, the above might be easier to understand

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close