User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 426,662 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,524 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser: Programming Forums
Views: 708 | Replies: 5
Reply
Join Date: May 2008
Posts: 3
Reputation: Porsche.V is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Porsche.V Porsche.V is offline Offline
Newbie Poster

can't convert data into char

  #1  
May 26th, 2008
if i use the query
SELECT iditem, CONVERT(char(20), dt, 105) FROM planeamento

it works just fine.. but in this case the dt (date) field is not recognised..

SELECT planeamento.iditem, idmodelo, item_planeamento.idproduto, item_planeamento.idpele, cor, ordemfabrico, qtd, CONVERT(char(20), dt, 105) FROM produto INNER JOIN item_planeamento ON produto.idproduto = item_planeamento.idproduto INNER JOIN  planeamento ON item_planeamento.iditem = planeamento.iditem WHERE planeamento.idfabrica = 51 AND alterado = 'FALSE' AND estado = NULL GROUP BY planeamento.iditem, produto.idModelo, item_planeamento.idProduto, item_planeamento.idPele, item_planeamento.cor, item_planeamento.ordemFabrico, item_planeamento.qtd, planeamento.dt

Can anyone see what's wrong?

thanks a lot for your help
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,189
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 931
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: can't convert data into char

  #2  
May 26th, 2008
It doesn't work because planeamento table is not in the FROM clause. Correct the query by specifying the planeamento as you did in other places
CONVERT(char(20), planeamento.dt, 105)
Last edited by Ancient Dragon : May 26th, 2008 at 10:11 am.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: May 2008
Posts: 3
Reputation: Porsche.V is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Porsche.V Porsche.V is offline Offline
Newbie Poster

Re: can't convert data into char

  #3  
May 26th, 2008
hum, but my previous query was the same but without the convert, so, was just

SELECT planeamento.iditem, idmodelo, item_planeamento.idproduto, item_planeamento.idpele, cor, ordemfabrico, qtd, DT FROM .......

and it printed the dt fine, but int the wrong format, that's why i am trying to convert it.. i assumed that if dt prints well, why don't the convert works? i tried like you said:

CONVERT(char(20), planeamento.dt, 105)

but was the same..

thanks for your help!
Last edited by Porsche.V : May 26th, 2008 at 10:38 am.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,189
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 931
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: can't convert data into char

  #4  
May 26th, 2008
>>but was the same..
You mean the convert was the same as without convert? If that is true then the 105 must be the wrong format specifier. I don't have the books so you will have to look up the format you want.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: May 2008
Posts: 3
Reputation: Porsche.V is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Porsche.V Porsche.V is offline Offline
Newbie Poster

Re: can't convert data into char

  #5  
May 26th, 2008
just found the problem.. i needed

CONVERT(char(20), planeamento.dt, 105) AS dt

everything was correct but i wasn't "giving" a name to the column i was converting

thanks a lot for your help
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: can't convert data into char

  #6  
May 26th, 2008
Originally Posted by Porsche.V View Post
if i use the query
SELECT iditem, CONVERT(char(20), dt, 105) FROM planeamento

it works just fine.. but in this case the dt (date) field is not recognised..

SELECT planeamento.iditem, idmodelo, item_planeamento.idproduto, item_planeamento.idpele, cor, ordemfabrico, qtd, CONVERT(char(20), dt, 105) FROM produto INNER JOIN item_planeamento ON produto.idproduto = item_planeamento.idproduto INNER JOIN  planeamento ON item_planeamento.iditem = planeamento.iditem WHERE planeamento.idfabrica = 51 AND alterado = 'FALSE' AND estado = NULL GROUP BY planeamento.iditem, produto.idModelo, item_planeamento.idProduto, item_planeamento.idPele, item_planeamento.cor, item_planeamento.ordemFabrico, item_planeamento.qtd, planeamento.dt

Can anyone see what's wrong?

thanks a lot for your help


Hi Porsch

You are joining various tables. Are you sure that dt exists only in table planeamento? If not, dt must be qualified (as like as in group-by clause: planeamento.dt).

krs,
tesu
Last edited by tesuji : May 26th, 2008 at 12:49 pm.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS SQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 1:52 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC