 |
| 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
|
|
|
|

May 23rd, 2007, 08:06 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 23rd, 2007, 08:20 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
================================================== =========
|
|

May 23rd, 2007, 10:39 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 23rd, 2007, 10:45 AM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
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
================================================== =========
|
|

May 23rd, 2007, 10:46 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
================================================== =========
|
|

May 24th, 2007, 04:27 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 347
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks guys, I think I got there in the end with your help.
|
|
 |