mercredi 4 février 2015

How to add numeric value as seconds to a datetime field and report data in new column

I need to convert the ElapsedTime field into hours/minutes/seconds and add that to the creationtime field and have the results reported into a new column that I'll call EndTime. Here is the query I have to gather the data:



select ElapsedTime, ChannelUsed, documents.creationtime from historytrx (nolock) inner join history on historytrx.handle = history.handle inner join documents on history.owner = documents.handle inner join DocFiles on documents.docfiledba = docfiles.handle where creationtime > '2015-02-02 20:00:00.000' and creationtime < '2015-02-02 20:01:00.000' and RemoteServer = 'DMG4120-01668' and ElapsedTime != '0'


Here is the current output:



ElapsedTime ChannelUsed creationtime
1042 1 2015-02-02 20:00:03.000
27 35 2015-02-02 20:00:05.000
57 50 2015-02-02 20:00:05.000


Here is my desired output:



ElapsedTime ChannelUsed creationtime EndTime
1042 1 2015-02-02 20:00:03.000 2015-02-02 20:17:39.000
27 35 2015-02-02 20:00:05.000 2015-02-02 20:00:32.000
57 50 2015-02-02 20:00:05.000 2015-02-02 20:01:03.000


Thanks to everyone in advance for any assistance.


mardi 3 février 2015

sql query is giving repeatative data


select a.invoice_no,
a.item_no ,
b.item ,
(a.invoice_qty * b.per_qty),
c.std_purchase_price
from shp..dms_t_invoice_item a
left outer join pmddb..bom_stock_tb b
on b.fg = a.item_no
left outer join pomdb..pur_vendor_stock c
on c.stock_no = b.item
where a.acsd_date between '2014-04-01 00:00:00.000' and '2014-04-30 00:00:00.000'
order by a.invoice_no

SQL statement to select from 2 different tables, from two different databases (same server)

How do I select from multiple tables in different databases on the same server?


Also, Is there a way to have an identifying marker so I could see where the results came from?


So for example:



SELECT db1.table1.name, db2.table2.name, fromTbl
FROM db1.table1, db2.table2
WHERE db1.table1.name LIKE '%j%' OR db2.table2.name LIKE '%j%'


So in this case, I'm selecting the names from 2 different databases and tables. I'm doing a wildcard search on those names and the fromTbl would let me know where the results came from?



4 john smith 4 555.555.5555 table1
17 joe schmoe 17 555.555.5555 table2
11 james doe 11 555.555.5555 table1


I'm using SQL Server 2005. Thanks for the input!


I've lost a scalar function in Access 2010 - how do I put it back? (I have the function in SQL)

I have a form in Access 2010 (.adp, not .accdb) that references a function titled dbo.search which seems to be missing. I am getting this error:


Cannot find either column "dbo" or the user-defined function or aggregate "dbo.search", or the name is ambiguous.


I cannot find the function "search" in the navigation pain, so I think I need to add it back. I have the function in a SQL 2005 database - what do I do?


lundi 2 février 2015

One Query 2 Joins

From my main table, I want to show all applicable dates from the calendar table and only show data that does not exist in the Branch table. This is the query I am trying, but it is returning way more results that it should be. Did I do a join incorrectly? Should I be using a sub-query or CTE instead?



Select
'Master' As [Type],
Main.EmployeeID,
Main.BankName,
Main.BankEmployeeName,
Main.Title,
Main.loan_status,
Cal.[Month],
Cal.[Year],
Main.LoanOfficer
From dbo.Calendar Cal
Inner Join MainBankInformation Main
On Cal.[Month] = Main.LoanMonth
Left Join BranchBankInformation Branch
On Main.EmployeeID = Branch.EmployeeID
And Main.loan_status IN ('approved', 'complete', 'final')

dimanche 1 février 2015

Build Calendar With Quarters Included

I know how to build a SQL Calendar with month & Year. But I need to also add Quarters into the calendar which I'm not sure how to set-up. For example, sample data output would need to be Q1 January February March Q2 April May June Q3 July August September Q4 October November December


What is the best syntax for creating a calendar with quarter information, or how could my syntax be tweaked to add in the quarter information as well? This is what I am currently using



Declare @startdate DateTime, @enddate DateTime;
Select @startdate = '2014-01-01', @enddate = '2016-12-31'
;With Num1 (n) As (
Select 1 as n
Union All Select n+1 as n
From Num1 Where n<101),
Num2 (n) As (Select 1 From Num1 As X, Num1 As Y),
Nums (n) As (Select Row_Number() Over(Order By n) From Num2)

,myDateCTE As
(Select Cast(dateadd(day,n-1,@startdate) as date) dt
from Nums)

Select dt, datename(month, dt) from myDateCTE
Where dt <= @enddate

remote connection to sql database

What is the connection string which connect remotely to sql database via visual studio c. Net