Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
Create Proc ProcDate 

as

Begin

Select

td.id , tod.OrderDetails  , td.[REPLACE(CONVERT(VARCHAR(20),DATEFROM,106),' ','-') + ' TO ' + REPLACE(CONVERT(VARCHAR(20),DATETO,106),' ','-')] AS [TOTAL ORDER RANGE DATE] 

FROM  tblDate td INNER JOIN tblOrderDetails tod 

ON   td.id = tod.id 

END 



While running above query i am getting the following error as '

Invalid column name 'REPLACE(CONVERT(VARCHAR(20),DATEFROM,106),' ','-') + ' TO ' + REPLACE(CONVERT(VARCHAR(20),DATETO,106),' ','-')'.
Posted
Updated 26-Oct-12 21:43pm
v2

i am assuming that datefrom and dateto are in tblDate table.

now try below code :

SQL
Create Proc ProcDate

as

Begin

Select

td.id , tod.OrderDetails  , [REPLACE(CONVERT(VARCHAR(20),td.DATEFROM,106),' ','-') + ' TO ' + REPLACE(CONVERT(VARCHAR(20),td.DATETO,106),' ','-')] AS [TOTAL ORDER RANGE DATE]

FROM  tblDate td INNER JOIN tblOrderDetails tod

ON   td.id = tod.id

END
 
Share this answer
 
try below code :

SQL
Create Proc ProcDate
 
as
 
Begin
 
Select
 
td.id , tod.OrderDetails  , REPLACE(CONVERT(VARCHAR(20),td.DATEFROM,106),' ','-') + ' TO ' + REPLACE(CONVERT(VARCHAR(20),td.DATETO,106),' ','-') AS [TOTAL ORDER RANGE DATE]
 
FROM  tblDate td INNER JOIN tblOrderDetails tod
 
ON   td.id = tod.id
 
END


mark as solution if it is helpful to you.
 
Share this answer
 
Showing following error again

Invalid column name 'REPLACE(CONVERT(VARCHAR(20),td.DATEFROM,106),' ','-') + ' TO ' + REPLACE(CONVERT(VARCHAR(20),td.DATETO,106),' ','-')'.
 
Share this answer
 
Comments
Bhushan Shah1988 27-Oct-12 3:48am    
Please tell me in which table Dateto and Datefrom are??
lalitkr 27-Oct-12 4:06am    
This both the DateTo and DateFrom are from the same table TblDate
Sergey Alexandrovich Kryukov 16-May-13 11:39am    
This not an answer, this is fake. And self-accepting it as an answer is just cheating.
—SA
I have Two Table tblOrder and tblOrderDetails

For the TblDate Having data as

Column_name Type
Id int
DateTo datetime
DateFrom datetime
OrderNumber varchar (50)

For the table tblOrderDetails

Column_name Type
id int
OrderDetails varchar(50)

I am Creating a Stored Proc on these two tables and fetching the result as shown in the proc and in result i want to merge the DateTo and DateFrom and show the result in the new column which not exist and also data not exist

Sample Data i am using

select * from tblOrderDetails
select * from tblDate

id OrderDetails
1 400
2 500
3 450
4 580


Id DateTo DateFrom OrderNumber
1 2012-10-27 07:55:35.857 2012-10-28 07:55:35.857 2222
11 2012-10-29 07:56:00.263 2012-10-31 07:56:00.263 1254
2 2012-11-07 08:13:41.247 2012-10-31 08:13:41.247 154
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900