Solved

use @strAll in SQL/vb.net

Posted on 2014-10-13
3
352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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 34

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL syntax for max(date) 3 39
mssql 7 32
Intermittent OleDbConnection Error 20 53
Access - convert query for SQL Server 5 12
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

752 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