Showing posts with label written. Show all posts
Showing posts with label written. Show all posts

Tuesday, March 27, 2012

date queries

I have written a report that contains multiple queries that displays the
number of applications we submit month by month to various entities. I wrote
the report last year and have been asked to create it again this year.
I know that this is going to be require every year, and I don't want to
write it again.
My problem is that in order to get the month by month data, I had to write
"WHERE (tDocHistory.ChangeDate BETWEEN '1/1/2008' AND '2/1/2008')
GROUP BY tDocHistory.NewStatus, tDocHistory.ChangeDate, tCompany.CoName,
tApplication.ApplicationNum, CONVERT(CHAR(2), DATEPART(MM,
tDocHistory.ChangeDate)), CONVERT(CHAR(4),
DATEPART(yyyy, tDocHistory.ChangeDate)), tApplication1028.MarkUpAmt"
I would like to be able to allow my users to select the year they wish to
view.
I wanted to replace the 2008 with % in the statement:
(tDocHistory.ChangeDate BETWEEN '1/1/%' AND '2/1/%')
and then filter the datepart for the year by writing:
HAVING (tDocHistory.NewStatus = 'wv' OR
tDocHistory.NewStatus = 'dcs') AND (tCompany.CoName
LIKE @.FunderName) AND (CONVERT(CHAR(4), DATEPART(yyyy,
tDocHistory.ChangeDate))
LIKE @.Year)
Do you know any way I could make this work?
--
SamyraWhy dont you use report parameter to select the date.
On Jan 12, 8:28=A0pm, Samyra <Sam...@.discussions.microsoft.com> wrote:
> I have written a report that contains multiple queries that displays the
> number of applications we submit month by month to various entities. =A0I =wrote
> the report last year and have been asked to create it again this year.
> I know that this is going to be require every year, and I don't want to
> write it again.
> My problem is that in order to get the month by month data, I had to =A0wr=ite
> "WHERE =A0 =A0 (tDocHistory.ChangeDate BETWEEN '1/1/2008' AND '2/1/2008')
> GROUP BY tDocHistory.NewStatus, tDocHistory.ChangeDate, tCompany.CoName,
> tApplication.ApplicationNum, CONVERT(CHAR(2), DATEPART(MM,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tDocHistory.ChangeDate)), CONV=ERT(CHAR(4),
> DATEPART(yyyy, tDocHistory.ChangeDate)), tApplication1028.MarkUpAmt"
> I would like to be able to allow my users to select the year they wish to
> view.
> I wanted to replace the 2008 with % in the statement:
> =A0 (tDocHistory.ChangeDate BETWEEN '1/1/%' AND '2/1/%')
> and then filter the datepart for the year by writing:
> HAVING =A0 =A0 =A0(tDocHistory.NewStatus =3D 'wv' OR
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 tDocHistory.NewStatus =3D 'dcs=') AND (tCompany.CoName
> LIKE @.FunderName) AND (CONVERT(CHAR(4), DATEPART(yyyy,
> tDocHistory.ChangeDate))
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 LIKE @.Year)
> Do you know any way I could make this work?
> --
> Samyra|||I would love to, but the report is built with text boxes with a separate
query in each box.
I am looking at a table that contains historical data for each record in the
database, not current data, so I wasn't able to build a table or a matrix
report that would display the data they wanted to see.
--
Samyra
"Sridar K" wrote:
> Why dont you use report parameter to select the date.
> On Jan 12, 8:28 pm, Samyra <Sam...@.discussions.microsoft.com> wrote:
> > I have written a report that contains multiple queries that displays the
> > number of applications we submit month by month to various entities. I wrote
> > the report last year and have been asked to create it again this year.
> >
> > I know that this is going to be require every year, and I don't want to
> > write it again.
> >
> > My problem is that in order to get the month by month data, I had to write
> >
> > "WHERE (tDocHistory.ChangeDate BETWEEN '1/1/2008' AND '2/1/2008')
> > GROUP BY tDocHistory.NewStatus, tDocHistory.ChangeDate, tCompany.CoName,
> > tApplication.ApplicationNum, CONVERT(CHAR(2), DATEPART(MM,
> > tDocHistory.ChangeDate)), CONVERT(CHAR(4),
> > DATEPART(yyyy, tDocHistory.ChangeDate)), tApplication1028.MarkUpAmt"
> >
> > I would like to be able to allow my users to select the year they wish to
> > view.
> >
> > I wanted to replace the 2008 with % in the statement:
> > (tDocHistory.ChangeDate BETWEEN '1/1/%' AND '2/1/%')
> >
> > and then filter the datepart for the year by writing:
> >
> > HAVING (tDocHistory.NewStatus = 'wv' OR
> > tDocHistory.NewStatus = 'dcs') AND (tCompany.CoName
> > LIKE @.FunderName) AND (CONVERT(CHAR(4), DATEPART(yyyy,
> > tDocHistory.ChangeDate))
> > LIKE @.Year)
> >
> > Do you know any way I could make this work?
> >
> > --
> > Samyra
>

Sunday, March 25, 2012

Date paramter default value

Hello all,
I have written a report that I would like to be sent to a person or
persons at the beginning of the week. There are two parameters in the
report that the users would normally type the dates. I know I can to the
previous week thing by using a stored procedure, but I would like to
know how I can, at report design time, give those parameters a default
date. I would like to try and use a non-queried value expression like:
=CDATE(dateadd("dd",-7,NOW())) for the start date and
=CDATE(dateadd("dd",-2,NOW())) for the end date
Would this be a valid approach?
Thanks,
Jeff JonesJeffrey Jones wrote:
> Hello all,
> I have written a report that I would like to be sent to a person or
> persons at the beginning of the week. There are two parameters in the
> report that the users would normally type the dates. I know I can to the
> previous week thing by using a stored procedure, but I would like to
> know how I can, at report design time, give those parameters a default
> date. I would like to try and use a non-queried value expression like:
> =CDATE(dateadd("dd",-7,NOW())) for the start date and
> =CDATE(dateadd("dd",-2,NOW())) for the end date
> Would this be a valid approach?
> Thanks,
> Jeff Jones
Okay...I was able to get the default thing to work. I used
=CDATE(MONTH(NOW()) & "/" & DatePart("d",DateAdd("d",-1,NOW())) & "/" &
YEAR(NOW())). Now I seem to be having a bit of a time problem on my
reporting server. My time seems to be set to UTC and I need it set to
US-Central time. Can anyone tell me how to do this? The server machine
time is correct, it is just the reporting server's output that is off.
Thanks,
Jeff Jones|||Take a look at the function ToLocalTime to convert from UTC. If the regional
settings (timezone) set on your reportserver differs from desired output
format you may have to specify timezone params in code.
=MyUTCDateTime.ToLocalTime()
"Jeffrey Jones" wrote:
> Jeffrey Jones wrote:
> > Hello all,
> > I have written a report that I would like to be sent to a person or
> > persons at the beginning of the week. There are two parameters in the
> > report that the users would normally type the dates. I know I can to the
> > previous week thing by using a stored procedure, but I would like to
> > know how I can, at report design time, give those parameters a default
> > date. I would like to try and use a non-queried value expression like:
> > =CDATE(dateadd("dd",-7,NOW())) for the start date and
> > =CDATE(dateadd("dd",-2,NOW())) for the end date
> > Would this be a valid approach?
> > Thanks,
> > Jeff Jones
> Okay...I was able to get the default thing to work. I used
> =CDATE(MONTH(NOW()) & "/" & DatePart("d",DateAdd("d",-1,NOW())) & "/" &
> YEAR(NOW())). Now I seem to be having a bit of a time problem on my
> reporting server. My time seems to be set to UTC and I need it set to
> US-Central time. Can anyone tell me how to do this? The server machine
> time is correct, it is just the reporting server's output that is off.
> Thanks,
> Jeff Jones
>|||I'm new in Reporting Services. Could you please tell me how to use the
ToLocalTime Method within Reporting Services.
Thanks
"Frederik" wrote:
> Take a look at the function ToLocalTime to convert from UTC. If the regional
> settings (timezone) set on your reportserver differs from desired output
> format you may have to specify timezone params in code.
> =MyUTCDateTime.ToLocalTime()
> "Jeffrey Jones" wrote:
> > Jeffrey Jones wrote:
> > > Hello all,
> > > I have written a report that I would like to be sent to a person or
> > > persons at the beginning of the week. There are two parameters in the
> > > report that the users would normally type the dates. I know I can to the
> > > previous week thing by using a stored procedure, but I would like to
> > > know how I can, at report design time, give those parameters a default
> > > date. I would like to try and use a non-queried value expression like:
> > > =CDATE(dateadd("dd",-7,NOW())) for the start date and
> > > =CDATE(dateadd("dd",-2,NOW())) for the end date
> > > Would this be a valid approach?
> > > Thanks,
> > > Jeff Jones
> > Okay...I was able to get the default thing to work. I used
> > =CDATE(MONTH(NOW()) & "/" & DatePart("d",DateAdd("d",-1,NOW())) & "/" &
> > YEAR(NOW())). Now I seem to be having a bit of a time problem on my
> > reporting server. My time seems to be set to UTC and I need it set to
> > US-Central time. Can anyone tell me how to do this? The server machine
> > time is correct, it is just the reporting server's output that is off.
> > Thanks,
> > Jeff Jones
> >

Sunday, March 11, 2012

date formatting or localization

I have written this ugly expression because I didn't know any other way. What I am trying to do is convert an English date string to a French string.

example

January 2005 > Janvier 2005

Thank you,

Pavel

=Switch(

Month(CDate(Fields!Month.Value) ) = 1, "Janvier" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 2, "Fevrier" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 3, "Mars" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 4, "Avril" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 5, "Mai" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 6, "Juin" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 7, "Juillet" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 8, "Aout" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 9, "September" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 10, "Octobre" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 11, "November" & " " & Year(CDate(Fields!Month.Value)),
Month(CDate(Fields!Month.Value) ) = 12, "December" & " " & Year(CDate(Fields!Month.Value))

)The only thing I see wrong with this is that you have Year(CDate(Fields!Month.Value) and that will not produce a result, correct?|||The field Month.Value stores "January 2004". I get the value from Analysis Services.

Pavel

Thursday, March 8, 2012

Date Format Problem - SQL Server Insert From Web Application

Hi,
I've written a short aspx file so that end users can insert lines into our
SQL server database. The following string is sent by Internet Explorer to
the database where it updates the relevant table -
INSERT INTO Tbl_Manual([Data Date],[Staff ID], Flag1, Flag2, Flag3, Ref1,
Ref2, Timestamp, Inputter) values('15/05/2005', '89', '1', '0', '0', '77',
'8', '01/05/2005 08:54:10', 'HOME\username')
The 2nd date is sent as a string into an nvarchar field so it causes no
problems but the first (which is heading for a datetime field) is assumed by
SQL to be MM/dd/yyyy format no matter what I try to do. All regional
settings are set to UK English & the table in SQL correctly uses dd/MM/yyyy
format so the above insert command fails thinking that I'm trying to add a
date of the 5th of month 15.
If I try input a date as mm/dd/yyyy format into the aspx page, an error is
thrown back.
Any ideas as to what's going wrong ?
Thanks
SteveYou can set date in an universal format 'yyyymmdd',
or use convert(datetime,'dd/mm/yyyy',103) function, see MS SQL Help or
http://www.karaszi.com/SQLServer/info_datetime.asp
Vlastik
"Steve" <steve.henderson@.btinternet.c0m> pe v diskusnm pspvku
news:uBIy7ljTFHA.2520@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I've written a short aspx file so that end users can insert lines into our
> SQL server database. The following string is sent by Internet Explorer to
> the database where it updates the relevant table -
> INSERT INTO Tbl_Manual([Data Date],[Staff ID], Flag1, Flag2, Flag3, Ref1,
> Ref2, Timestamp, Inputter) values('15/05/2005', '89', '1', '0', '0', '77',
> '8', '01/05/2005 08:54:10', 'HOME\username')
> The 2nd date is sent as a string into an nvarchar field so it causes no
> problems but the first (which is heading for a datetime field) is assumed
by
> SQL to be MM/dd/yyyy format no matter what I try to do. All regional
> settings are set to UK English & the table in SQL correctly uses
dd/MM/yyyy
> format so the above insert command fails thinking that I'm trying to add a
> date of the 5th of month 15.
> If I try input a date as mm/dd/yyyy format into the aspx page, an error is
> thrown back.
> Any ideas as to what's going wrong ?
> Thanks
> Steve
>|||Steve
Always use 'YYYYMMDD' to insert data into SQL Server table. To display dates
use FORMAT or other functions to format to be suitable to the client.
"Steve" <steve.henderson@.btinternet.c0m> wrote in message
news:uBIy7ljTFHA.2520@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I've written a short aspx file so that end users can insert lines into our
> SQL server database. The following string is sent by Internet Explorer to
> the database where it updates the relevant table -
> INSERT INTO Tbl_Manual([Data Date],[Staff ID], Flag1, Flag2, Flag3, Ref1,
> Ref2, Timestamp, Inputter) values('15/05/2005', '89', '1', '0', '0', '77',
> '8', '01/05/2005 08:54:10', 'HOME\username')
> The 2nd date is sent as a string into an nvarchar field so it causes no
> problems but the first (which is heading for a datetime field) is assumed
by
> SQL to be MM/dd/yyyy format no matter what I try to do. All regional
> settings are set to UK English & the table in SQL correctly uses
dd/MM/yyyy
> format so the above insert command fails thinking that I'm trying to add a
> date of the 5th of month 15.
> If I try input a date as mm/dd/yyyy format into the aspx page, an error is
> thrown back.
> Any ideas as to what's going wrong ?
> Thanks
> Steve
>|||Date formats are set on the connection level in SQL Server, not database or
server wide. If they are not explicitly set, they are derived from the
default settings for the login that uses the connection. It appears to me
that the login you use to connect to the database has it's language (which
also includes the date format)set to British, but the login that you web app
uses to connect to the database, has it language set to English, i.e. U.S.
English.
Jacco Schalkwijk
SQL Server MVP
"Steve" <steve.henderson@.btinternet.c0m> wrote in message
news:uBIy7ljTFHA.2520@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I've written a short aspx file so that end users can insert lines into our
> SQL server database. The following string is sent by Internet Explorer to
> the database where it updates the relevant table -
> INSERT INTO Tbl_Manual([Data Date],[Staff ID], Flag1, Flag2, Flag3, Ref1,
> Ref2, Timestamp, Inputter) values('15/05/2005', '89', '1', '0', '0', '77',
> '8', '01/05/2005 08:54:10', 'HOME\username')
> The 2nd date is sent as a string into an nvarchar field so it causes no
> problems but the first (which is heading for a datetime field) is assumed
> by SQL to be MM/dd/yyyy format no matter what I try to do. All regional
> settings are set to UK English & the table in SQL correctly uses
> dd/MM/yyyy format so the above insert command fails thinking that I'm
> trying to add a date of the 5th of month 15.
> If I try input a date as mm/dd/yyyy format into the aspx page, an error is
> thrown back.
> Any ideas as to what's going wrong ?
> Thanks
> Steve
>|||I suggest that you read up about SQL Code Injection once you have this
resolved. The implication from your question is that data is more or less
coming off a web form straight into the database and as such may be highly
vulnerable to hacking.
"Steve" <steve.henderson@.btinternet.c0m> wrote in message
news:uBIy7ljTFHA.2520@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I've written a short aspx file so that end users can insert lines into our
> SQL server database. The following string is sent by Internet Explorer to
> the database where it updates the relevant table -
> INSERT INTO Tbl_Manual([Data Date],[Staff ID], Flag1, Flag2, Flag3, Ref1,
> Ref2, Timestamp, Inputter) values('15/05/2005', '89', '1', '0', '0', '77',
> '8', '01/05/2005 08:54:10', 'HOME\username')
> The 2nd date is sent as a string into an nvarchar field so it causes no
> problems but the first (which is heading for a datetime field) is assumed
> by SQL to be MM/dd/yyyy format no matter what I try to do. All regional
> settings are set to UK English & the table in SQL correctly uses
> dd/MM/yyyy format so the above insert command fails thinking that I'm
> trying to add a date of the 5th of month 15.
> If I try input a date as mm/dd/yyyy format into the aspx page, an error is
> thrown back.
> Any ideas as to what's going wrong ?
> Thanks
> Steve
>|||Thanks Jacco - You got it in one. You have no idea how long I've been trying
to fix this!!!
I'd set a local account up on the server for testing things - trust
Microsoft to default things to 'english' which being from England myself I
would have assumed to be correct rather than having to choose 'British
English' !
Steve
"Jacco Schalkwijk" <jacco.please.reply@.to.newsgroups.mvps.org.invalid> wrote
in message news:u39qoyjTFHA.3184@.TK2MSFTNGP15.phx.gbl...
> Date formats are set on the connection level in SQL Server, not database
> or server wide. If they are not explicitly set, they are derived from the
> default settings for the login that uses the connection. It appears to me
> that the login you use to connect to the database has it's language (which
> also includes the date format)set to British, but the login that you web
> app uses to connect to the database, has it language set to English, i.e.
> U.S. English.
> --
> Jacco Schalkwijk
> SQL Server MVP
>
> "Steve" <steve.henderson@.btinternet.c0m> wrote in message
> news:uBIy7ljTFHA.2520@.TK2MSFTNGP09.phx.gbl...
>|||>
> I'd set a local account up on the server for testing things - trust
> Microsoft to default things to 'english' which being from England myself I
> would have assumed to be correct rather than having to choose 'British
> English' !
>
LOL|||The original poster might consider a parameterized query. This will address
both the SQL injection security issue as well as date string formatting.
Hope this helps.
Dan Guzman
SQL Server MVP
"Mercury" <me@.spam.com> wrote in message
news:d52dsi$ac7$1@.lust.ihug.co.nz...
>I suggest that you read up about SQL Code Injection once you have this
>resolved. The implication from your question is that data is more or less
>coming off a web form straight into the database and as such may be highly
>vulnerable to hacking.
>
> "Steve" <steve.henderson@.btinternet.c0m> wrote in message
> news:uBIy7ljTFHA.2520@.TK2MSFTNGP09.phx.gbl...
>|||> The original poster might consider a parameterized query. This will
> address both the SQL injection security issue as well as date string
> formatting.
I may go on to look at that but I'm currently not too bothered about hacking
attempts as the form is for intranet use only - I just need something quick
& dirty !
Thanks
Steve

Wednesday, March 7, 2012

Date Format

I have a written a stored procedure and excecuting it and displaying it in gridview(ASP.NET). I am getting Birthdate in the form of8/23/1956 12:00:00 AM. I just need8/23/1956. I have defined it as smalldatetime in stored procedure. How can I get it in that format ?

HELP.......

In your .net code, if the object is of type DateTime you can call ToShortDate.

|||

Either you can convert the datetime to a varchar in your stored procedure:

select convert(varchar(10), getdate(), 103)

... or you can format the output in the GridView:

<asp:BoundFieldDataField="now"DataFormatString="{0:dd/MM/yyyy}"HtmlEncode="false"/>

|||

Set the DataFormatString, either in designer or HTML:

<asp:BoundField DataField="Date" DataFormatString="{0:dd-MMM-yy}" HeaderText="Date" HtmlEncode="false" />
|||

You can read more about CONVERT here:http://msdn2.microsoft.com/en-us/library/aa226054(SQL.80).aspx

...and more about DataFormatString here:http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx

|||

Thanks a bunch ... millepag

That CONVERT thing worked for me!!!!