SQL LanguageSQL 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 .
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?
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
================================================== =========
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?
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.
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
================================================== =========