Data Conversion in SQL server 2008

Asked

Viewed 74 times

1

Hello! I need to do a data conversion in SQL Server 2008 from the "data field".

Could someone tell me how this can be done?

I tried so:

    select distinct c.Empresa, p.Nome, 
CONVERT(VARCHAR(19),getdate(),105),
c.NumeroOC as 'Numero da OC', c.Fornecedor as 'Cod Fornecedor', pe.Nome as 'Fornecedor', 
(Convert(Numeric(10,2), c.valor)) as 'Valor',
det.descricao as 'Local de Entrega',l.Descricao as 'CR',
Case when c.situacao = 1 then
    'Pendente'
    when c.situacao = 2 then
    'Atendida Parcialmente'
    when c.situacao = 3 then
    'Atendida Totalmente'
    when c.situacao = 4 then
    'Finalizada Manualmente' end as 'Status',
c.ordemaut as 'Gerada Sem Processo', 
ic.Cotacao,
so.NumeroSolic as 'Número Solicitação', ic.Material,
m.Descricao,
c.Obs
from compras c
inner join pessoas p on (c.empresa = p.codigo)
inner join pessoas pe on (c.fornecedor = pe.codigo)
inner join locais l on (c.cresultado = l.codigo) and tipolocal = 'CR'
inner join detpessoas det on (det.Sequencial = c.LocalEntrega)
inner join itenscompra ic on (c.SequencialOC = ic.SequencialOC)
inner join Materiais m on (ic.Material = m.codigo)
inner join ItensSolic its on (ic.cotacao = its.cotacao)
inner join solicitacoes so on (its.SequencialSolic = so.SequencialSolic)
order by c.data, ic.material

But he’s bringing the current date, I couldn’t figure out where to fit the column he should convert.

  • GETDATE() returns the current date, replace with its field.

  • I tried this, it gives this problem: Message 4121, Level 16, Status 1, Line 1 Unable to locate the "c" column or the user-defined function or the"c.Data" aggregate, or the name is ambiguous.

  • Sorry, but my crystal ball is offline and I am not able to read the command you are using. See: Manual on how NOT to ask questions

  • And like the column C.DATA was declared?

  • Reading suggestion: Dominating dates and times in SQL Server -> https://portosql.wordpress.com/2020/02/29/dominando-datas-horas/

2 answers

1

If the column C.DATA was declared as datetime and the goal is to display the date in the dd-mm-yyyy format, try

SELECT c.Empresa, p.Nome, 
       convert (char(10), c.DATA, 105) as Data,
       c.NumeroOC as 'Numero da OC', 
       ...

-2

try using a CONVERT(DATE, GETDATE()) DATA or CAST(GETDATE() as DATE) DATE

  • I tried running select distinct c.Company, p.Name, CAST(c.Data() as DATE) DATA, c. Name 'Vendor', (Convert(Numeric(10,2), c.value)) 'Value', det.Description 'Place of Delivery',l. Description 'CR',... But he says it’s ambiguous.

  • You have provided an ambiguous name and are therefore in conflict with another name.

  • After all c.Data is a field of your table or is it a function?

  • It is a name of a field of my table

  • Then put this () after the name of the field because its presence indicates a function without parameters.

  • In the comment above: s/put/remove/

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.