Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 23rd, 2007, 08:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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




Reply With Quote
  #2 (permalink)  
Old May 23rd, 2007, 08:20 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old May 23rd, 2007, 10:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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

Reply With Quote
  #4 (permalink)  
Old May 23rd, 2007, 10:45 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 63 Times in 63 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
================================================== =========
Reply With Quote
  #5 (permalink)  
Old May 23rd, 2007, 10:46 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
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
================================================== =========
Reply With Quote
  #6 (permalink)  
Old May 24th, 2007, 04:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
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.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02:00 PM
Query String Cast or Convert function hoffmann Access 6 February 25th, 2004 12:58 PM



All times are GMT -4. The time now is 05:33 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.