|
-
Jan 11th, 2011, 06:15 PM
#1
Thread Starter
Addicted Member
VBNET2008 SQLSERVER 2000 SQL string
Hullo Good Guys, 
I need your help. Please help me.
I am using VBNET2008 and SQL SERVER 2000.
I tried to create this SQL string to retrieve CustomerID and a CustomerID and Name together but it's not working
Here are the SQL String that is not working.
Dim strsql As String = ""
strsql &= "Select CustomerID, "
strsql &= " ( CustomerID & " - " & CompanyName ) as [Companyname]"
strsql &= " From TestCustomers Order by CompanyName"
This is the error message
Conversion from string "Select CustomerID, CustomerID & " to type 'Double' is not valid.
Cause by this SQL String coding:
strsql &= " CustomerID & " - " & CompanyName as [Companyname]"
I am using the NORTHWIND DatacBase in SQL SERVER 2000 and the table is Customers
Last edited by Lennie; Jan 11th, 2011 at 06:17 PM.
Reason: type error
-
Jan 11th, 2011, 07:21 PM
#2
Re: VBNET2008 SQLSERVER 2000 SQL string
Look at this part:
Code:
" ( CustomerID & " - " & CompanyName ) as [Companyname]"
Does that look like a valid String to you?
-
Jan 11th, 2011, 07:26 PM
#3
Re: VBNET2008 SQLSERVER 2000 SQL string
that's because after your ampersand, you drop out of the string and then have a - ... which means subtract... so it tries to convert your string to a double to perform the arithmetic operation... but since the string can't be converted to a double, the error results.
Going out on a limb, I'm going to guess that what you're trying to do is concatenate the ID with the company name with a - in the middle, right?
Try this:
Code:
strsql &= " ( CustomerID & ' - ' & CompanyName ) as [Companyname]"
changed the " to ' around the -
-tg
-
Jan 11th, 2011, 07:54 PM
#4
Re: VBNET2008 SQLSERVER 2000 SQL string
 Originally Posted by techgnome
that's because after your ampersand, you drop out of the string and then have a - ... which means subtract... so it tries to convert your string to a double to perform the arithmetic operation... but since the string can't be converted to a double, the error results.
Going out on a limb, I'm going to guess that what you're trying to do is concatenate the ID with the company name with a - in the middle, right?
Try this:
Code:
strsql &= " ( CustomerID & ' - ' & CompanyName ) as [Companyname]"
changed the " to ' around the -
-tg
Also, SQL Server doesn't use & to concatenate strings. That's a VB thing. T-SQL uses the more usual +. & is a bitwise AND.
-
Jan 11th, 2011, 08:18 PM
#5
Thread Starter
Addicted Member
Re: VBNET2008 SQLSERVER 2000 SQL string
Jmcilhinney,
You suggestion of sample code: strsql &= " ( CustomerID & ' - ' & CompanyName ) as [Companyname]"
is not the way that I requested as per my posting earlier.
This is what I wanted as per Business Analyst specficatino and requirements:
strsql &= "CustomerID,"
strsql &= " ( CustomerID & ' - ' & CompanyName ) as [Companyname]"
-
Jan 11th, 2011, 08:58 PM
#6
Re: VBNET2008 SQLSERVER 2000 SQL string
Hang on... time out... you're saying the "wrong" solution that you don't want... is the same as the requirement... did I miss something?
-tg
-
Jan 11th, 2011, 09:05 PM
#7
Thread Starter
Addicted Member
Re: VBNET2008 SQLSERVER 2000 SQL string
techgnome
Your suggestion is similar to one from Jmcilhinney without complete SQL String that I posted.
Because of that I could not understand it. Please try to be complete.
-
Jan 11th, 2011, 09:26 PM
#8
Re: VBNET2008 SQLSERVER 2000 SQL string
That's because that's the only line that's the problem... just simply fix the line you have...
-tg
-
Jan 12th, 2011, 07:54 AM
#9
Re: VBNET2008 SQLSERVER 2000 SQL string
The line
strsql &= " ( CustomerID & " - " & CompanyName ) as [Companyname]"
should be this:
strsql &= " ( CustomerID + ' - ' + CompanyName ) as [Companyname]"
Is CustomerID as numeric or text field?
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|