Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 VBS - Inner joins

Author  Topic 

mcninja
Starting Member

3 Posts

Posted - 2007-06-26 : 08:34:09
Hi all, I have a question to do with pulling data from an SQL server using vbscript. Apologies if I am posting in the wrong place but the problem I am having seems to be related to INNER JOIN.

This is my script:

sql = "SELECT UserGroup.UserGroupName, User.UserName FROM (UserInUserGroup INNER JOIN UserGroup ON UserInUserGroup.UserGroupId = UserGroup.UserGroupId) INNER JOIN User ON UserInUserGroup.UserId = User.UserId WHERE UserGroup.UserGroupName 'Int*'"

This SQL statement came from a working query in Access 2003... So it may not port across to VBS well ?

I'm actually trying to pull from a WebMarshal database but I keep getting an error:

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1:Incorrect Syntax near '.'.

Now this error occurs on the client which is setup to talk to the SQL database through a system DSN. I can get simple data no problem so I am assuming the System DSN is setup correctly. Do I need to put table names in [] ?

All help and advice gratefully received.

Thanks,

Mat

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-26 : 08:40:06
[code]WHERE UserGroup.UserGroupName = 'Int*'[/code]

If you want to find all occurrences that start with word Int, then use LIKE as below:

[code]WHERE UserGroup.UserGroupName Like 'Int%'[/code]


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

mcninja
Starting Member

3 Posts

Posted - 2007-06-26 : 09:06:19
Hi - thanks for your feedback but unfortunately no luck. like a lemon I missed out the "Like" statement which should have been in the first post.

I tried both suggestions but I get the same error message detailed above.

This code works fine with only 1 INNER JOIN:

sql = "SELECT UserGroup.UserGroupName FROM (UserInUserGroup INNER JOIN UserGroup ON UserInUserGroup.UserGroupId = UserGroup.UserGroupId) WHERE UserGroup.UserGroupName Like 'Int*'"

But I need both Joins to get the data I want and with or without brackets, I can't seem to get both Joins to work ?

Is the User join a problem because of the keyword "User" ?

Regards,

Mat
Go to Top of Page

mcninja
Starting Member

3 Posts

Posted - 2007-06-26 : 10:16:52
Ok - sorry to all you folks out there who wanted to help me on this but I think I have fixed it. The problem seems to be the word "user" - this must be reserved so I have put it in [] and now the query seems to be producing what I was expecting....

I never knew that
Go to Top of Page
   

- Advertisement -