How to create a SQL-statement over more rows in code

davy_g

Well-known member
Joined
Jul 18, 2007
Messages
63
Location
Belgium
Programming Experience
Beginner
Hi,

I'm writing a program in which I select data from a table in SQL Server 2005, but where my SQL-statement becomes long.
Therefore, for a good overview, I want to split my SELECT-statement over more rows.

How can I split this into more rows?

sql = "SELECT bla bla .... FROM ... WHERE .... IN (SELECT ... FROM .... WHERE .... AND status = 10) bla bla"

When I set this in 1 row it becomes hard to read because I have to scroll all the time.

Is there a way to set this statement into more rows?

e.g.
SELECT ....
FROM ....
WHERE .....
....
 
Each of the commands (like InsertCommand property etc) of the DataAdapter have a Parameters collection you can set.
 
Using the DataAdapter to set the parameters.

If you post the problematic code, I'll fix it.

I expect it would go something like:

VB.NET:
Public Function PrepareCommand(sql As String, params as Object) as OleDbCommand

  Dim x as New OleDbCommand(sql)

  For Each o as Object in params
    If TypeOf(o) is String Then
      x.Parameters.Add(o.GetHashCode().ToString(), OleDbType.VarChar).Value = o
    Else If TypeOf(o) is Integer or TypeOf(o) is Double Then
      x.Parameters.Add(o.GetHashCode().ToString(), OleDbType.Number).Value = o
    Else If TypeOf(o) is Date Then
      x.Parameters.Add(o.GetHashCode().ToString(), OleDbType.DateTime).Value = o
    End If
  Next o

  Return x
End Function
 
Back
Top