Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > SQL results


Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2003, 07:26 AM
mam0014 mam0014 is offline
Newcomer
 
Join Date: Sep 2002
Location: Texas
Posts: 10
Default SQL results


I am putting this sql statement into my program and I get no results, but if I run it through ISQLW I do get results any ideas?

SQL
-------------------------------------------------------------------
SELECT distinct VR.VIDEO_ID
FROM mpeg..VIDEOS_REQUIRED VR
JOIN mpeg..VIDEOS_REQUIRED_TEXT VT ON VR.STATUS = VT.STATUS
LEFT JOIN mpeg..VIDEO VD ON VD.VIDEO_ID = VR.VIDEO_ID
LEFT JOIN mpeg..VIDEOS_ARCHIVED VA ON VA.VIDEO_ID = VR.VIDEO_ID
LEFT JOIN mpeg..VIDEOS_ARCHIVED_TEXT VAT ON VA.STATUS = VAT.STATUS
where VD.VIDEO_ID = null and VAT.VALUE <> null
---------------------------------------------------------------------

VB Code
----------------------------------------------------------------------
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim Qy As New ADODB.Command
Dim sql As String
Dim ConnectionString As String
ConnectionString = "driver={SQL Server};" & _
"server=CTCDB1; uid=sa; pwd=; database=mpeg;"


With cn
.ConnectionString = ConnectionString
.ConnectionTimeout = 10
.Open
End With


Dim i%
Dim tst As Boolean
Dim tst1 As Boolean
Dim log$


sql = "SELECT distinct VR.VIDEO_ID"
sql = sql + vbCrLf + "FROM mpeg..VIDEOS_REQUIRED VR"
sql = sql + vbCrLf + "JOIN mpeg..VIDEOS_REQUIRED_TEXT VT ON VR.STATUS = VT.STATUS"
sql = sql + vbCrLf + "LEFT JOIN mpeg..VIDEO VD ON VD.VIDEO_ID = VR.VIDEO_ID"
sql = sql + vbCrLf + "LEFT JOIN mpeg..VIDEOS_ARCHIVED VA ON VA.VIDEO_ID = VR.VIDEO_ID"
sql = sql + vbCrLf + "LEFT JOIN mpeg..VIDEOS_ARCHIVED_TEXT VAT ON VA.STATUS = VAT.STATUS"
sql = sql + vbCrLf + "where VD.VIDEO_ID = null and VAT.VALUE <> null"
Text2.Text = sql
rs.Open sql, cn
On Error Resume Next
Do Until rs.EOF
List1.AddItem rs.Fields(0)
rs.MoveNext
Loop
rs.Close

End Sub
----------------------------------------------------------------------

Any suggestions?

Thanks
Reply With Quote
  #2  
Old 04-22-2003, 07:55 AM
burningice96's Avatar
burningice96 burningice96 is offline
Junior Contributor
 
Join Date: Apr 2003
Location: Montreal
Posts: 270
Default

SQL isn't picky about line breaks. As long as there are spaces between the different commands (that's all it sees a line break as, a space), the query will run fine. I've heard of people having problems with vbCrLf before. Why don't you try replacing your vbCrLf's with a " "?
Reply With Quote
  #3  
Old 04-22-2003, 08:32 AM
DrPunk's Avatar
DrPunk DrPunk is online now
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,275
Default

If you want to use Carriage returns in SQL statements then use vbCR instead of vbCrLf (i.e. just a carriage return, and no line feed on the end). It's a good idea to use them if you are outputting your query some where for a person to read (even just the debug window) so that it formats the queries nice to read.

Your code would look much better type as so

Code:
sql = "SELECT distinct VR.VIDEO_ID" & vbcr & _ "FROM mpeg..VIDEOS_REQUIRED VR" & vbcr & _ "JOIN mpeg..VIDEOS_REQUIRED_TEXT VT ON VR.STATUS = VT.STATUS" & vbcr & _ "LEFT JOIN mpeg..VIDEO VD ON VD.VIDEO_ID = VR.VIDEO_ID" & vbcr & _ "LEFT JOIN mpeg..VIDEOS_ARCHIVED VA ON VA.VIDEO_ID = VR.VIDEO_ID" & vbcr & _ "LEFT JOIN mpeg..VIDEOS_ARCHIVED_TEXT VAT ON VA.STATUS = VAT.STATUS" & vbcr & _ "where VD.VIDEO_ID = null and VAT.VALUE <> null"

This makes it much easier to read the query within the code. Please note the "_" at the end of every line which tells VB that the line does not finish at the end of the current line, but continues to the next, until there isn't a "_"

To try and fix your problem, what database are you connecting to? I guess it isn't Access!

Oh, yeah, I see, it's an SQL Server. OK, first guess, is it the double dots (i.e. mpeg..VIDEOS_...). Will it work with one dot (i.e. mpeg.VIDEOS_...)
Reply With Quote
  #4  
Old 04-22-2003, 02:37 PM
mam0014 mam0014 is offline
Newcomer
 
Join Date: Sep 2002
Location: Texas
Posts: 10
Default

I can actually completely remove the mpeg.. because I set the database in my connection string. But, still no luck I am getting no return. Would it have anything to do with the JOIN's? I am just grasping now. I have tried it line by line and I get some sort of result until I use the where clause.

where VD.VIDEO_ID = null and VAT.VALUE <> null

Doesn't make sense that it would work in ISQLw, but not from VB.

Oh Well I keep trying.

Thanks
Reply With Quote
  #5  
Old 05-14-2003, 12:14 PM
Briotti Briotti is offline
Newcomer
 
Join Date: May 2003
Location: Rome
Posts: 8
Default

Quote:
Originally Posted by mam0014


where VD.VIDEO_ID = null and VAT.VALUE <> null




I don't remember (i work with several database engines and each one has his own statement for "null") if it is correct for MSSQL:

where VD.VIDEO_ID = null and VAT.VALUE <> null

Try instead

where VD.VIDEO_ID isnull and not(VAT.VALUE isnull)

or something like this

where isnull(VD.VIDEO_ID) and not(isnull(VAT.VALUE))

check the statement syntax

Bye

Giuseppe
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL error in Vb Code blong824 Database and Reporting 16 03-14-2004 05:07 PM
Problem with writing Twice Renidrag Web Programming 20 11-07-2002 02:52 PM
Unstable sql select results monjeos Database and Reporting 5 08-07-2002 01:31 AM
Creating Access Databases TomGuy Database and Reporting 8 07-10-2002 10:56 AM
merging the results from 2 sql queries ronhancock Database and Reporting 11 03-27-2002 09:28 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->