Wednesday, March 28, 2012
How do i limit number of rows in a table based on dates?
My application is written in c# and uses sql Express to store
information relating to what time employees clock in/out of work each
day.
How can i restrict the amount of rows in my attendance database table
so that entries older than 3 months are automatically deleted from the
database?
Thanks in advance!
KHi
I'd create a stored procedure that does deletion and then create a
job(weekly...) that will run this SP
<kls.systems@.btinternet.com> wrote in message
news:1176719432.941536.219550@.o5g2000hsb.googlegroups.com...
> Hi,
> My application is written in c# and uses sql Express to store
> information relating to what time employees clock in/out of work each
> day.
> How can i restrict the amount of rows in my attendance database table
> so that entries older than 3 months are automatically deleted from the
> database?
> Thanks in advance!
> K
>|||Thanks for the help uri, I thought that sql express couldnt use
scheduled jobs though as it doesnt use sql agent?
Thanks again.|||Ah I see, did not read properly your post
Perhaps here you will find some info
Automating Database maintenance in SQL 2005 Express Edition Part I
http://www.sqldbatips.com/showarticle.asp?ID=27
Automating Database maintenance in SQL 2005 Express Edition Part II
http://www.sqldbatips.com/showarticle.asp?ID=29
<kls.systems@.btinternet.com> wrote in message
news:1176721669.824203.42940@.l77g2000hsb.googlegroups.com...
> Thanks for the help uri, I thought that sql express couldnt use
> scheduled jobs though as it doesnt use sql agent?
> Thanks again.
>|||How about using a .sql script file, execute it using SQLCMD (in a .bat file) and use the Windows
scheduler to execute that .bat file?
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
<kls.systems@.btinternet.com> wrote in message
news:1176721669.824203.42940@.l77g2000hsb.googlegroups.com...
> Thanks for the help uri, I thought that sql express couldnt use
> scheduled jobs though as it doesnt use sql agent?
> Thanks again.
>|||On 16 Apr, 12:22, "Uri Dimant" <u...@.iscar.co.il> wrote:
> Ah I see, did not read properly your post
> Perhaps here you will find some info
> Automating Database maintenance in SQL 2005 Express Edition Part Ihttp://www.sqldbatips.com/showarticle.asp?ID=27
> Automating Database maintenance in SQL 2005 Express Edition Part IIhttp://www.sqldbatips.com/showarticle.asp?ID=29
> <kls.syst...@.btinternet.com> wrote in message
> news:1176721669.824203.42940@.l77g2000hsb.googlegroups.com...
>
> > Thanks for the help uri, I thought that sql express couldnt use
> > scheduled jobs though as it doesnt use sql agent?
> > Thanks again.- Hide quoted text -
> - Show quoted text -|||Thanks very much for all of your help, I'll try setting up a windows
scheduled job to run an sql script to do this as suggested in the
articles you provided links for.
I just thought there would have been a quick and easy setting within
management studio express i could configure to do it but nevermind!
Thanks very much again for your help Uri, very much appreciated.
Friday, March 23, 2012
How do I include all dates between 2 parameters in a table?
(for example, a count of something) in a certain date range and others
do not. The problem I am having is that I need each page of the report
to show all the possible dates and the display a 0 when there are no
values for the date. Currently it is dropping that date.
For Example:
@.StartDate = 1/1/06
@.EndDate = 6/31/06
-- I get this on grouped values where there are empty months:
Jan06 5
Feb06 3
Apr06 7
Jun06 10
-- But I want this:
Jan06 5
Feb06 3
Mar06 0
Apr06 7
May06 0
Jun06 10
Due to other report properties and calculations, I can't really modify
my query to fix this problem. It seems like it should be easy to solve
but I'm not getting it!!!
Thanks.I think you must be using table control. so no way you can substitute 0 for
missing one. you need to modify query to use right join to include all the
rows.
if you hard code all the months value still you need to change the query to
get all the rows to column..
Try to change query, rather than breaking head.
Amarnath
"CanoAko" wrote:
> I'm working with a data set where some values have an aggretate total
> (for example, a count of something) in a certain date range and others
> do not. The problem I am having is that I need each page of the report
> to show all the possible dates and the display a 0 when there are no
> values for the date. Currently it is dropping that date.
> For Example:
> @.StartDate = 1/1/06
> @.EndDate = 6/31/06
> -- I get this on grouped values where there are empty months:
> Jan06 5
> Feb06 3
> Apr06 7
> Jun06 10
> -- But I want this:
> Jan06 5
> Feb06 3
> Mar06 0
> Apr06 7
> May06 0
> Jun06 10
> Due to other report properties and calculations, I can't really modify
> my query to fix this problem. It seems like it should be easy to solve
> but I'm not getting it!!!
> Thanks.
>|||Hmm... that doesn't really help. I admit now that I will probably have
to design a query to do it. The problem is that the query joins 2
tables and the date that I'm pulling is on the second table. So the
date doesn't exist to do an aggregate with a total of 0 in the first
place.
I'm going to try it with CASE to force it to happen, but I'm not too
excited about that. I've only been doing this for a month so I still
haven't figured everything out.
Amarnath wrote:
> I think you must be using table control. so no way you can substitute 0 for
> missing one. you need to modify query to use right join to include all the
> rows.
> if you hard code all the months value still you need to change the query to
> get all the rows to column..
> Try to change query, rather than breaking head.
> Amarnath
>
> "CanoAko" wrote:
> > I'm working with a data set where some values have an aggretate total
> > (for example, a count of something) in a certain date range and others
> > do not. The problem I am having is that I need each page of the report
> > to show all the possible dates and the display a 0 when there are no
> > values for the date. Currently it is dropping that date.
> >
> > For Example:
> >
> > @.StartDate = 1/1/06
> > @.EndDate = 6/31/06
> >
> > -- I get this on grouped values where there are empty months:
> > Jan06 5
> > Feb06 3
> > Apr06 7
> > Jun06 10
> >
> > -- But I want this:
> > Jan06 5
> > Feb06 3
> > Mar06 0
> > Apr06 7
> > May06 0
> > Jun06 10
> >
> > Due to other report properties and calculations, I can't really modify
> > my query to fix this problem. It seems like it should be easy to solve
> > but I'm not getting it!!!
> >
> > Thanks.
> >
> >|||Hi,
thats quite easy, use the following link to see how to generate a
calendar table, you can either persits it or create it on the fly.
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-calendar-table.html
HTH, Jens K. Suessmeyer.
--
http://www.sqlserver2005.de
--
Monday, March 19, 2012
How do I get DESC order?
Hey guys, I have a view with dates (TheDate) meant to be arranged in descending order. When I 'Execute SQL' while in the view, the DESC order works just fine and shows up with the latest date first going down. However, once I 'OPEN VIEW' the order keeps defaulting to ASCending order.
How do I keep it in DESC order for viewing? Here's the statement:
SELECT TOP (100) PERCENT TheDate
FROM dbo.MyDates
ORDER BY TheDate DESC
By the way, I'm using SQL Server Express, if it makes any difference.
|||hi,
views, as tables, do not have an order at all.. in fact yoe are executing a SELECT ... FROM view .. ORDER BY ...;
this is the relevant (!) step in your requirement.. the order by clause is a cursor task, not associated with the underlying table/view.. data inside a table (on which the view is defined) is not ordered
please have a look at wikipedia and here as well, where you can read
"..A view is a relational table, and the
relational model states that a table is a set of rows. Since sets are not sorted - per definition - the rows in a view are not ordered either. .."
and even
".. A view is a logical relational table, and the relational model mandates that a table is a set of rows, implying no sort order whatsoever. .."
so, what you are getting, is correct..
if you like, you can "open" the view (in SSMSE) and apply the required "sort" clause adding the ORDER BY specs..
regards
|||
Andrea Montanari wrote:
hi,
views, as tables, do not have an order at all.. in fact yoe are executing a SELECT ... FROM view .. ORDER BY ...;
this is the relevant (!) step in your requirement.. the order by clause is a cursor task, not associated with the underlying table/view.. data inside a table (on which the view is defined) is not ordered
please have a look at wikipedia and here as well, where you can read
"..A view is a relational table, and the
relational model states that a table is a set of rows. Since sets are not sorted - per definition - the rows in a view are not ordered either. .."and even
".. A view is a logical relational table, and the relational model mandates that a table is a set of rows, implying no sort order whatsoever. .."
so, what you are getting, is correct..
if you like, you can "open" the view (in SSMSE) and apply the required "sort" clause adding the ORDER BY specs..
regards
Thank you for the very informative response as well as the links, Andrea. I was starting to go insane wondering what I was missing! Another day another lesson, I guess!
Once again, thanks for the info.
Monday, March 12, 2012
How do I format data in the SQL statement
dates and text in SQL Server statements, can't find much in online books ,
Where can I relearn this, thanks
JimThat's a little vague but I think you are after CONVERT(). See BooksOnLine
for more details.
Andrew J. Kelly SQL MVP
"Jim Warren" <jmwarren@.msu.edu> wrote in message
news:u0WUchlCFHA.392@.TK2MSFTNGP14.phx.gbl...
> It has been a couple of years but I remember being able to format numbers,
> dates and text in SQL Server statements, can't find much in online books
> ,
> Where can I relearn this, thanks
> Jim
>|||Sorry
How do I make Number into zero decimal point i.e. 2.0000000 into 2. How do I
convert dates from 2005-1-14 to Jan 1, 2005. Is there a format statement of
some kind
Thanks
Jim
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:O9sU4llCFHA.1292@.TK2MSFTNGP10.phx.gbl...
> That's a little vague but I think you are after CONVERT(). See
> BooksOnLine for more details.
> --
> Andrew J. Kelly SQL MVP
>
> "Jim Warren" <jmwarren@.msu.edu> wrote in message
> news:u0WUchlCFHA.392@.TK2MSFTNGP14.phx.gbl...
>|||Yes. It's called CONVERT().
mk:@.MSITStore:C:\Program%20Files\Microso
ft%20SQL%20Server\80\Tools\Books\tsq
lref.chm::/ts_ca-co_2f3o.htm
However, CONVERT will not handle your first requirement. You will need to do
that in your client application.
PS. dates are not stored with any format. They are stored as pairs of
integers. You really need to start reading in Books Online (BOL)
Jim Warren wrote:
> Sorry
> How do I make Number into zero decimal point i.e. 2.0000000 into 2.
> How do I convert dates from 2005-1-14 to Jan 1, 2005. Is there a
> format statement of some kind
> Thanks
> Jim
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:O9sU4llCFHA.1292@.TK2MSFTNGP10.phx.gbl...
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"|||As I stated and Bob confirmed you would want to look at CONVERT() in
BooksOnLine. You can convert the decimal into an INT and that will loos the
decimal places.
Andrew J. Kelly SQL MVP
"Jim Warren" <jmwarren@.msu.edu> wrote in message
news:OI$46h3CFHA.1836@.tk2msftngp13.phx.gbl...
> Sorry
> How do I make Number into zero decimal point i.e. 2.0000000 into 2. How do
> I convert dates from 2005-1-14 to Jan 1, 2005. Is there a format statement
> of some kind
> Thanks
> Jim
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:O9sU4llCFHA.1292@.TK2MSFTNGP10.phx.gbl...
>
Sunday, February 19, 2012
How do I display SQL Server 1/1/1900 dates as blank in Access?
that SQL Server 2005 considers a blank date as blank rather than as
"1/1/1900"? I know I can create a function like that shown below to do it.
Public Function BlankDate(datInputDate)
If datInputDate < #1/2/1900# Then
BlankDate = ""
Else
BlankDate = datInputDate
End If
End Function
I'm just hoping there's a simpler more universal way to do it, either on the
Access side or the SQL Server 2005 side.
Thanks!
Michael
I thought that blank date was null.
You could try in your query using:
nullif(FieldName, '1/1/1900') as FieldName
Note that this will not be updatable.
Russel Loski, MCSD.Net
"Michael Nagan" wrote:
> Is there an easy way to tell Access (2000 or 2003) to display the "1/1/1900"
> that SQL Server 2005 considers a blank date as blank rather than as
> "1/1/1900"? I know I can create a function like that shown below to do it.
> Public Function BlankDate(datInputDate)
> If datInputDate < #1/2/1900# Then
> BlankDate = ""
> Else
> BlankDate = datInputDate
> End If
> End Function
> I'm just hoping there's a simpler more universal way to do it, either on the
> Access side or the SQL Server 2005 side.
> Thanks!
> Michael
>
>
How do I display SQL Server 1/1/1900 dates as blank in Access?
that SQL Server 2005 considers a blank date as blank rather than as
"1/1/1900"? I know I can create a function like that shown below to do it.
Public Function BlankDate(datInputDate)
If datInputDate < #1/2/1900# Then
BlankDate = ""
Else
BlankDate = datInputDate
End If
End Function
I'm just hoping there's a simpler more universal way to do it, either on the
Access side or the SQL Server 2005 side.
Thanks!
MichaelI thought that blank date was null.
You could try in your query using:
nullif(FieldName, '1/1/1900') as FieldName
Note that this will not be updatable.
--
Russel Loski, MCSD.Net
"Michael Nagan" wrote:
> Is there an easy way to tell Access (2000 or 2003) to display the "1/1/1900"
> that SQL Server 2005 considers a blank date as blank rather than as
> "1/1/1900"? I know I can create a function like that shown below to do it.
> Public Function BlankDate(datInputDate)
> If datInputDate < #1/2/1900# Then
> BlankDate = ""
> Else
> BlankDate = datInputDate
> End If
> End Function
> I'm just hoping there's a simpler more universal way to do it, either on the
> Access side or the SQL Server 2005 side.
> Thanks!
> Michael
>
>
How do I display SQL Server 1/1/1900 dates as blank in Access?
that SQL Server 2005 considers a blank date as blank rather than as
"1/1/1900"? I know I can create a function like that shown below to do it.
Public Function BlankDate(datInputDate)
If datInputDate < #1/2/1900# Then
BlankDate = ""
Else
BlankDate = datInputDate
End If
End Function
I'm just hoping there's a simpler more universal way to do it, either on the
Access side or the SQL Server 2005 side.
Thanks!
MichaelI thought that blank date was null.
You could try in your query using:
nullif(FieldName, '1/1/1900') as FieldName
Note that this will not be updatable.
--
Russel Loski, MCSD.Net
"Michael Nagan" wrote:
> Is there an easy way to tell Access (2000 or 2003) to display the "1/1/190
0"
> that SQL Server 2005 considers a blank date as blank rather than as
> "1/1/1900"? I know I can create a function like that shown below to do it
.
> Public Function BlankDate(datInputDate)
> If datInputDate < #1/2/1900# Then
> BlankDate = ""
> Else
> BlankDate = datInputDate
> End If
> End Function
> I'm just hoping there's a simpler more universal way to do it, either on t
he
> Access side or the SQL Server 2005 side.
> Thanks!
> Michael
>
>