Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

use @strAll in SQL/vb.net

Posted on 2014-10-13
3
Medium Priority
?
365 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 800 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 35

Accepted Solution

by:
ste5an earned 1200 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

705 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