Writing SQL command text in BO


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
What is the cleanest, suggested way to write SQL commands in code in a BO or a class?

I have the following code which works, but it may be hard to either debug or understand at a later time:

Dim cmd As New SqlCommand()

cmd.CommandText = "SELECT DISTINCT dbo.SC_Appliances.* " & _

"FROM dbo.SC_Appliances " & _

"RIGHT OUTER JOIN dbo.ServiceCalls ON (dbo.SC_Appliances.FK_ServiceCalls = dbo.ServiceCalls.PK_ServiceCalls) " & _

"WHERE " & _

"(dbo.ServiceCalls.Status NOT IN (" & ServiceCallStatus.Done & "," & ServiceCallStatus.Void & ")) AND " & _

"(dbo.SC_Appliances.ServicedDate = @pServiceCallsScheduleDate);"

cmd.Parameters.AddWithValue("@pServiceCallsScheduleDate", serviceCallsScheduleDate).SqlDbType = SqlDbType.DateTime

Return cmd

Basically that will translate to this:

SELECT DISTINCT dbo.SC_Appliances.* 

FROM dbo.SC_Appliances

RIGHT OUTER JOIN dbo.ServiceCalls ON (dbo.SC_Appliances.FK_ServiceCalls = dbo.ServiceCalls.PK_ServiceCalls)

WHERE

(dbo.ServiceCalls.Status NOT IN (2,3)) AND

(dbo.SC_Appliances.ServicedDate = @pServiceCallsScheduleDate);



Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Edhy Rijo - 17 Years Ago
Trent L. Taylor - 17 Years Ago
             Got you, thank!
Edhy Rijo - 17 Years Ago
Greg McGuffey - 17 Years Ago
                     Good comments, Greg. I agree.
Trent L. Taylor - 17 Years Ago
Edhy Rijo - 17 Years Ago
                         My pleasure Edhy.

I've also modified a tool like this to...
Greg McGuffey - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search