Solved

Sqlserver 2005 query syntax help

Posted on 2008-06-25
9
196 Views
Last Modified: 2010-04-21
I have
+ convert(varchar(10), getdate(), 112)

which is part of a concantonated query

it yields:

20080625

for its piece

I need it to show:

062508

Thanks in advance
0
Comment
Question by:MyDanes
  • 4
  • 3
9 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21867344

select replace(convert(varchar(10), getdate(),10),'-','')
0
 
LVL 8

Expert Comment

by:sbagireddi
ID: 21867364
SELECT REPLACE (CONVERT(varchar(10),getdate(),1),'/','')
0
 

Author Comment

by:MyDanes
ID: 21867399
Ok that did not work I got an error - I should have put the entire section which is:

select top 100 percent '2',right('0000000000' + cast(payment_id as varchar(10)),10) +
       right('0000000000' + replace(cast(amount as varchar(10)),'.',''),10) + '355008765102873' + convert(varchar(10), getdate(),10),'-','') as result
from CASHMGMT_PAYMENT

ONLY need to fix the getdate part so my output for the getdate portion shows:
062508

0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21867433
you forgot the 2nd replace:



select top 100 percent '2',right('0000000000' + cast(payment_id as varchar(10)),10) +
       right('0000000000' + replace(cast(amount as varchar(10)),'.',''),10) + '355008765102873' + replace(convert(varchar(10), getdate(),10),'-','') as result
from CASHMGMT_PAYMENT
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 60

Expert Comment

by:chapmandew
ID: 21867456
huh?  why did you pick that one over mine?  your syntax was wrong in your 2nd post.
0
 

Author Comment

by:MyDanes
ID: 21867527
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21867545
OK.  You just had me confused....thought I had answered something wrong.  :)
0
 

Author Closing Comment

by:MyDanes
ID: 31470646
Thanks Chapmando and sorry for the trouble
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now