Skip to main content
Announcements
Customer Spotlight: Discover what’s possible with embedded analytics Oct. 16 at 10:00 AM ET: REGISTER NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Problem creating a ODBC Connect string to loop through

We have several databases with the same structure that I want to loop through instead of repeating the same code. I've tried the following code but get a 'Data source name not found ....' error message. Any ideas welcome or alternative method.

[Code]
SET Connect1 = 'abz (XUserId is abc, XPassword is zxz)';
SET Connect2 = 'sca (XUserId is abc, XPassword is xyz)';
LET iCount =1;

For iCount = 1 to 2
LET ConnectStr = 'Connect' & iCount;

ODBC CONNECT TO [$(ConnectStr)];
SELECT {Select Code}

Next
[/Code]

1 Solution

Accepted Solutions
Not applicable
Author

Hi dendraw,

the value of your ConnectStr is (according to the LET of For..next) "connect1" or "connect2". But you want to get the value of the variable "connect1" or "connect2". So you need an additional statement (variable, sorry for the name ) like this:

For iCount = 1 to 2
LET TT= 'Connect' & iCount;
LET ConnectStr= $(TT);
//ODBC CONNECT TO [$(ConnectStr)];
//SELECT {Select Code}
Next


Regards, Roland

View solution in original post

2 Replies
Not applicable
Author

Hi dendraw,

the value of your ConnectStr is (according to the LET of For..next) "connect1" or "connect2". But you want to get the value of the variable "connect1" or "connect2". So you need an additional statement (variable, sorry for the name ) like this:

For iCount = 1 to 2
LET TT= 'Connect' & iCount;
LET ConnectStr= $(TT);
//ODBC CONNECT TO [$(ConnectStr)];
//SELECT {Select Code}
Next


Regards, Roland

Anonymous
Not applicable
Author

Hi Roland

Many thanks. I had to also remove the square brackets from around the string. Work great now. Smile. Right now I'm not sure why it has to be done to get the value of the variable but will work that through.

Regards, Dave Andrew