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