|
swoozie1 wrote: use a function that already exists for Last Business day of the month Maybe somneone already wrote one, but there's no such thing built in, AFAIK. What a "week" or "weekend" is, is determined by your locale, and a company may have multiple of those. Holidays are even more complex, and tend to change rather frequently.
Create a loop that inserts weekdays for your locale in a table; that way you have list with the weekends already eliminated. Next, delete every date in there that is mentioned in the holidays table (or join, or make a new table). Select the top result for that month.
There's your last theoretical work-day.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I use a view and a holiday table as I need to keep holidays for a number of countries/currencies. The view starts at the beginning of last year and goes for 10 years, arbitrarily picked by me, it has date part DayOfWeek so I can exclude weekends.
It will be fairly simple to combine the two as Eddy suggested, fiddling with the filters/joins to get the last working sate.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello .
I am quite a beginner in Sql Server, I am testing some simple sql code on Sql Server 2012.
I have a table called "AcctTransaction " composed by 4 columns :
AccountId as Int,
TransactionId as Int,
TransactionDate as DateTime,
Amount as Decimal (a8,4)
I am trying to make this simple query work :
SELECT AccountId
,SUM(Amount) OVER (PARTITION BY AccountId) AS FinalBalance
,SUM(Amount) OVER (PARTITION BY AccountId ORDER BY TransactionDate, TransactionId
) AS ProgressiveBalance
FROM AcctTransaction
I keep getting the following error :
Incorrect syntax near "order"
and in effect if I comment out the
,SUM(Amount) OVER (PARTITION BY AccountId ORDER BY TransactionDate, TransactionId ) AS ProgressiveBalance
statement, everything works correctly.
What's wrong with that statement ?
I've made this query copying almost identically a sql statement I saw in a Microsoft course, where it seems to work perfectly....
Thanks to everyone who would answer ...
modified 28-May-15 8:40am.
|
|
|
|
|
A sudden thought ... is it possibile that I am getting this error only because I am using the Express version of Sql Server 2012 ? Maybe the express version, being not complete, lacks the "LAG" function....
Just a random thought .....
|
|
|
|
|
Are you sure you're using SQL 2012? I've just tried an equivalent query on my copy of 2012 Express, and it works perfectly.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well, that's what it says on "Help | About" section from the top menu ....
Other infos are :
Microsoft SQL Server Management Studio 11.0.2100.60
Microsoft Data Access Components (MDAC) 6.1.7601.17514
Microsoft MSXML 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 9.11.9600.17801
Microsoft .NET Framework 4.0.30319.34209
Operating System 6.1.7601
Is it possible I have some components that's missing ?
|
|
|
|
|
You might be using SQL 2012 Management Studio, but are you connecting to a SQL 2012 instance?
Try running:
SELECT @@VERSION
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
You are right my friend .... executing the query you suggested I realized I am actually using Sql Server 2008 ....
and this maybe will solve some other problems I think I have ...
Thank you very much
|
|
|
|
|
I want to learn rdbms can anybody give me brief concept of RDBMS.
Thank you
|
|
|
|
|
Use a search engine; look for concepts. Start reading.
If you have a particular question, post your code/SQL statement here and someone will probably try to help.
|
|
|
|
|
|
What is your question? Where is your code? There are not enough details here.
|
|
|
|
|
That is not a question, it is an assignment; one that is lacking enough data to complete it.
If you need to dump data from table1 into table2, I'd recommend a single "select" statement. No need for cursors there. If you are wondering how to build a cursor, I'd recommend the examples on MSDN.
You're welcome.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
TSQL - Cursor[^]
TSQL - Select statement[^]
TSQL - Insert[^]
This is some links to the msdn documentation on various method that you will need to employ to complete your task as you have stated. BUT as others have stated I would also look into the SELECT INTO commands
TSQL - Select Into[^]
if you need more help after this please post your sql statements that you have you and describe the problem that you are facing. Sadly no one will be willing to just hand you the code without any effort.
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Your request is rude. Consider yourself lucky you got some pointers.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
modified 22-May-15 10:27am.
|
|
|
|
|
I want a code of java prog
which can take million integers as input,
sort them (bubble or quick or selection sort).
It should display time taken to sort first 10 integer, then for first 100 integer, then for 10000 and total.
Please help me soon I have very less time to complete my project.
iamsohail.srk@gmail.com
|
|
|
|
|
You'll have a greater chance of getting an answer if you post in the JAVA forum[^].
And when you do, be sure to say what you've tried and where you're stuck.
|
|
|
|
|
Sohail Sowell wrote: I want a code of java prog You can get help if you are stuck with a specific question on writing the code; but if you are looking for someone to do your work, this is the wrong place.
Good luck.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Your less time is not a problem for us. We are help to help, not to serve.
In Java integers have a limit. You cannot exceed those limits, otherwise you will face a problem known as "Integer Overflow" or "Integer Underflow". It depends on the size of that type, int or long etc. However, there is another special class in Java, BigInteger[^]. You can use it to overcome these limitations in Java.
Rest of the stuff are just fancy algorithm based functions. If you are well aware of these functions and algorithms then you can definitely write them yourself. What is so difficult in these problems? Learn more on them, https://en.wikipedia.org/wiki/Bubble_sort[^], https://en.wikipedia.org/wiki/Selection_sort[^], https://en.wikipedia.org/wiki/Quicksort[^].
Then use timer to check how long does it take to complete the task. Simple!
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: Learn more
I think this may be an invalid assumption
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want a code of java prog
which can take million integers as input,
sort them (bubble or quick or selection sort).
It should display time taken to sort first 10 integer, then for first 100 integer, then for 10000 and total.
Please help me soon I have very less time to complete my project.
iamsohail.srk@gmail.com
|
|
|
|
|
No, this is not how it works. We gladly help when you get stuck but we aren't going to do all your work for you.
You didn't even manage to post this in the correct forum.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I am using sql server 2005.
I have a column with date values (say column1). I need to fetch the date which does not exist in the past 15 days.
Means : user insert records daily. But on May 1st due to leave no records got inserted. So I need to analyse past 15 days (from current date) and fetch only May 1st.
I tried below query.But its return the past 15 days (excluding weekends). But i need days which not exist in past 15 days.
select distinct top 15 inserteddate from table1 where
((DATEPART(dw, inserteddate) + @@DATEFIRST) % 7) NOT IN (0, 1) and ( inserteddate >= DATEADD(DAY,-15,inserteddate) and inserteddate <= getdate())
order by inserteddate desc
Help me pls.
modified 11-May-15 9:22am.
|
|
|
|
|
I would suggest you create a temporary table with the dates for the last 15 days and then select the dates from the temporary table not in the table1 you referenced.
The temporary table can be populated using a while loop.
|
|
|
|
|
Realized you might need to go across month boundaries, so yes, I think generating a list dates 15 days back in a table variable and doing a datediff against those in a join might be the easiest solution.
|
|
|
|