Solved

use @strAll in SQL/vb.net

Posted on 2014-10-13
3
328 Views
Last Modified: 2014-10-14
In the code below, what I am trying to do is to determine what the value of str_All should be. And then trying to set @strAll = str_All so that I could use it in my SQL.

Question: How can I do something like this?
Dim str_All As String
If chkCustomersWithOrders.Checked Then
         str_All = "(have orders)"
Else
         str_All = "(some have orders)"
End If

 @strAll =str_All
 SQL.ExecQuery("SELECT CustomerID, substring(FirstName + ' ' + LastName + '                                                     ',1,50) +" & " dbo.fnHasOrders (CustomerID) as CustName From tblCustomers Union" & _
  " SELECT '99999', '<All>' + @strAll  From tblCustomers")

Open in new window

0
Comment
Question by:Mike Eghtebas
3 Comments
 
LVL 15

Assisted Solution

by:Haris Djulic
Haris Djulic earned 200 total points
ID: 40379273
Hi,

do you really need to pass the value strAll to @strAll, you can use it like this..

Dim str_All As String
If chkCustomersWithOrders.Checked Then
         str_All = "(have orders)"
Else
         str_All = "(some have orders)"
End If

 @strAll =str_All
 SQL.ExecQuery("SELECT CustomerID, substring(FirstName + ' ' + LastName + '                                                     ',1,50) +" & " dbo.fnHasOrders (CustomerID) as CustName From tblCustomers Union" & _
  " SELECT '99999', '<All>' + " & strAll & "  From tblCustomers")

Open in new window

0
 
LVL 32

Accepted Solution

by:
ste5an earned 300 total points
ID: 40379313
Use a parameterized query.

btw, please post concise and complete samples. What kind of type is SQL?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 40380396
samo4fun,

Just because I wanted to see how it is done via parameter, I was trying to use @strAll.


ste5an,

Yes, I should have mentioned SQLEXPRESS12

Mike
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now