Wrox Programmer Forums
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 23rd, 2007, 08:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default CAST function

I've got a SELECT statement with a cast function; the reason for the cast function is that one of my db fields is of data type 'text'.

This is the statement:

SELECT DISTINCT a.Artist, b.BiogID, b.DOB, b.DOD, CAST(b.Detail as varchar(8000)), 8000 AS 'Detail' FROM tbl_Biogs b, tbl_Pictures p, tbl_Artists a WHERE p.ArtistID = 44 AND b.ArtistID = p.ArtistID
AND a.ArtistID = b.ArtistID AND a.ArtistID = p.ArtistID


but the output of b.Detail returns 8000 and I need it to return the actual content of the b.Detail field. I'm not sure where I'm going wrong?

thanks




 
Old May 23rd, 2007, 08:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

CAST(b.Detail as varchar(8000)), 8000 AS 'Detail' this looks suspicious.. are you looking for the right field?? there is a 8000 that always show in a column named detail, and the column b.detail casted doesn't have a name...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 23rd, 2007, 10:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

I got you - sorry was casting the wrong field!

thanks

On another note, I have another question regarding DISTINCT.

I have a table in a db that has 8 fields; if one of those fields, the company name, is the same I only want to pull out one of those records; here's my statement I'm using:

SELECT DISTINCT AccountID, RegionID, Title, Name, Surname, Company, Address, Address2, Address3, Postcode, Telephone, Fax, Mobile, Email, Website, LEFT(CAST(Description as varchar(8000)), 8000) AS 'Description', LEFT(CAST(AddContact as varchar(8000)), 8000) AS 'AddContact', DateAdded, Sequence FROM Account ORDER BY Sequence, Company

but it still pulls out a duplicate 'Company' entry - how can I avoid it pulling out the duplicate?

thanks again

 
Old May 23rd, 2007, 10:45 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

That is not how DISTINCT works.

If you do:
SELECT DISTINCT Company from Account

This will return you every company name in the table 1 time however, if you do:

SELECT DISTINCT AccountID, Company From Account

Assuming accountID is a unique number, this will return you every row in your table because each row is distinct from one another because of the AccountID.

I am not quite sure how you will do this otherwise if you need to know the company of the account in question.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 23rd, 2007, 10:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

I don't follow you.. can you please post a little example of what you have and what you need??

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 24th, 2007, 04:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Adam H-W
Default

Thanks guys, I think I got there in the end with your help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Specified cast is not valid. ayem Visual Studio 2008 1 September 8th, 2008 09:15 PM
Specified cast is not valid heba ASP.NET 2.0 Professional 1 May 27th, 2007 08:51 PM
Dynamic Cast in C# jacob C# 15 September 25th, 2006 11:37 AM
Specified cast is not valid. abstar BOOK: ASP.NET Website Programming Problem-Design-Solution 2 March 31st, 2005 03:00 PM
Query String Cast or Convert function hoffmann Access 6 February 25th, 2004 01:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.