Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Friday, March 23, 2012

Making a SQL Update Query run once

I have a datagrid in my file along with an Update Query.
My Update Query basically adds the numerical values in two columnstogether when the page is loaded. This means whenever the page isRefreshed the Update query is fired.
This is my Update Query (which is in an Stored Procedure):
UPDATE Rental
SET TotalFee = ExtraFee + TotalFee
WHERE DaysOverdue >= 0
I have declared my query in the 'Page_Load' part of the coding, becauseI want the query to run automatically. Not manually by a button.
My main question is that how can I get the query to run only once a day, no matter how many times the page is loaded.
While I wouldn't recommend putting an update query in your page_Load,you can test for a postback before running the query by querying thePage.IsPostBack property: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassIsPostBackTopic.asp
|||The query will run whenever your page runs but you can force SQL Server to keep the compiled version of the query in the procedure cache by using the auto start option with sp_procoption system stored proc in the Master database. Run a search for sp_procotion in SQL Server BOL (books online). Hope this helps.|||

I would not have the query run by any ASP.NET page. What happens if no one visits the page in question some day? What happens when the site restarts?

Use DTS on the SQL Server and schedule a job to run once a day.

|||I think Doug is offering the best advice. It looks like you arecalculating late fees so you'd definitely want to run it every day.
If it doesn't matter whether or not it runs every day, and you simplywant it to run no more than once a day, I would add a datetime columnflagging the date on which it was last run. Then you could changeyour query like this:
DECLARE @.Today datetime
SELECT @.Today = GETDATE()
UPDATE Rental
SET TotalFee = ExtraFee + TotalFee,
DateFlagged = @.Today
WHERE DaysOverdue >= 0 AND
DateFlagged < CONVERT(char(8),@.Today,112)
Another option is to calculate the TotalFee on the fly,something like this, rather than updating it every day. Thiswould be safer and not dependent upon a process running every day (andI am guessing that DaysOverDue is also being populated by a process...):
SELECT TotalFee = TotalFee + (ExtraFee * DaysOverDue)
FROM Rental

|||Thanks for all your input.
But I think the best solution to my problem would be using this query:
DECLARE @.Today datetime
SELECT @.Today = GETDATE()
UPDATE Rental
SET TotalFee = ExtraFee + TotalFee,
DateFlagged = @.Today
WHERE DaysOverdue >= 0 AND
DateFlagged < CONVERT(char(8),@.Today,112)

But for some reason I cannot seem to get it to work. I have made anextra column in my table called 'DateFlagged'. I have tried to make itwork by creating this column data type as Date and char. But either wayit is not calculating the Total Fee.
I would appreciate any more info to make this query work.

|||DateFlagged should definitely be a datetime data type. Thiscolumn will initially contain a NULL if you do not set a default valuefor it, so any comparison against a value will return aFALSE. Therefore you'll need to check it for a NULL valueas well.
See if this helps:
WHERE DaysOverdue >= 0 AND
(DateFlagged < CONVERT(char(8),@.Today,112) OR DateFlagged IS NULL)

|||Yep! You solved my problem.
Thanks alot for all your help!

making a set of possible values for a column

I use to know how to do this in oracle, but cant remember... how do i set up
a constraint on a column in a table so it can say only be
"START","STOP","INPROG" only as the text that column can have? thanks!Brian
Does it relate to SQL Server ?
"Brian Henry" <nospam@.nospam.com> wrote in message
news:OZNGmLq7FHA.4076@.tk2msftngp13.phx.gbl...
>I use to know how to do this in oracle, but cant remember... how do i set
>up a constraint on a column in a table so it can say only be
>"START","STOP","INPROG" only as the text that column can have? thanks!
>|||yes? why wouldn't a constraint on a column relate to sql server
"Uri Dimant" <urid@.iscar.co.il> wrote in message
news:uIV5pPq7FHA.2176@.TK2MSFTNGP14.phx.gbl...
> Brian
> Does it relate to SQL Server ?
>
> "Brian Henry" <nospam@.nospam.com> wrote in message
> news:OZNGmLq7FHA.4076@.tk2msftngp13.phx.gbl...
>|||I not 100% shure but something like this should work !ALTER TABLE your_table
ADD CONSTRAINT CK_emp_id CHECK (colum_name='START' or colum_name='STOP' or
colum_name='INPROG')
Regards,Predrag Stojanovic"Brian Henry" <nospam@.nospam.com> wrote in message
news:OZNGmLq7FHA.4076@.tk2msftngp13.phx.gbl...
> I use to know how to do this in oracle, but cant remember... how do i set
up
> a constraint on a column in a table so it can say only be
> "START","STOP","INPROG" only as the text that column can have? thanks!
>|||Seems that you are looking for CHECK constraints.
Here is details about Check Constraint from BOL:
CHECK constraints enforce domain integrity by limiting the values that are
accepted by a column. They are similar to FOREIGN KEY constraints in that
they control the values that are placed in a column. The difference is in ho
w
they determine which values are valid: FOREIGN KEY constraints get the list
of valid values from another table, and CHECK constraints determine the vali
d
values from a logical expression that is not based on data in another column
.
For example, it is possible to limit the range of values for a salary column
by creating a CHECK constraint that allows only data that ranges from $15,00
0
through $100,000. This prevents salaries from being entered beyond the norma
l
salary range.
You can create a CHECK constraint with any logical (Boolean) expression that
returns TRUE or FALSE based on the logical operators. For the previous
example, the logical expression is:
salary >= 15000 AND salary <= 100000
And here is an example from BOL:
This example specifies that the pub_id must be within a specific list or
follow a given pattern. This constraint is for the pub_id of the publishers
table.
CHECK (pub_id IN ('1389', '0736', '0877', '1622', '1756')
OR pub_id LIKE '99[0-9][0-9]')
"Brian Henry" wrote:

> yes? why wouldn't a constraint on a column relate to sql server
>
> "Uri Dimant" <urid@.iscar.co.il> wrote in message
> news:uIV5pPq7FHA.2176@.TK2MSFTNGP14.phx.gbl...
>
>|||thanks thats what i was looking for
"Absar Ahmad" <AbsarAhmad@.discussions.microsoft.com> wrote in message
news:CBFE5462-107B-439B-B980-60882F0CA9FA@.microsoft.com...
> Seems that you are looking for CHECK constraints.
> Here is details about Check Constraint from BOL:
> CHECK constraints enforce domain integrity by limiting the values that are
> accepted by a column. They are similar to FOREIGN KEY constraints in that
> they control the values that are placed in a column. The difference is in
> how
> they determine which values are valid: FOREIGN KEY constraints get the
> list
> of valid values from another table, and CHECK constraints determine the
> valid
> values from a logical expression that is not based on data in another
> column.
> For example, it is possible to limit the range of values for a salary
> column
> by creating a CHECK constraint that allows only data that ranges from
> $15,000
> through $100,000. This prevents salaries from being entered beyond the
> normal
> salary range.
> You can create a CHECK constraint with any logical (Boolean) expression
> that
> returns TRUE or FALSE based on the logical operators. For the previous
> example, the logical expression is:
> salary >= 15000 AND salary <= 100000
> And here is an example from BOL:
> This example specifies that the pub_id must be within a specific list or
> follow a given pattern. This constraint is for the pub_id of the
> publishers
> table.
> CHECK (pub_id IN ('1389', '0736', '0877', '1622', '1756')
> OR pub_id LIKE '99[0-9][0-9]')
> "Brian Henry" wrote:
>sql

Wednesday, March 21, 2012

Making a column's values unique

I have an INTEGER column that I want to convert to a primary key. However,
some of the values currently in the dataset are not unique. What query will
delete any records with duplicate values of the intended index?
Many thanks!
http://www.sql-server-performance.com/rd_delete_duplicates.asp
http://www.sqlteam.com/item.asp?ItemID=3331
http://support.microsoft.com/kb/139444
Andrew J. Kelly SQL MVP
"Andrew Chalk" <achalk@.magnacartasoftware.com> wrote in message
news:eZld$eOkHHA.4628@.TK2MSFTNGP06.phx.gbl...
>I have an INTEGER column that I want to convert to a primary key. However,
>some of the values currently in the dataset are not unique. What query will
>delete any records with duplicate values of the intended index?
> Many thanks!
>
|||Thanks! This > http://www.sqlteam.com/item.asp?ItemID=3331 did the trick.
Regards,
Andrew
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:uzNZXBPkHHA.5048@.TK2MSFTNGP04.phx.gbl...
>
> http://www.sql-server-performance.com/rd_delete_duplicates.asp
> http://www.sqlteam.com/item.asp?ItemID=3331
> http://support.microsoft.com/kb/139444
>
> --
> Andrew J. Kelly SQL MVP
> "Andrew Chalk" <achalk@.magnacartasoftware.com> wrote in message
> news:eZld$eOkHHA.4628@.TK2MSFTNGP06.phx.gbl...
>
|||How to remove duplicate rows from a table in SQL Server
http://support.microsoft.com/kb/139444
'Microsoft SQL Server tables should never contain duplicate rows,
nor non-unique primary keys...Duplicate PKs are a violation of
entity integrity, and should be disallowed in a relational system.'
While it is not surprising that any vetting process (should it even
exist) at Redmond would allow this nonsense to seep through, what
is particular disturbing is how it could possibly pass through
at leading institutions of learning. One can only paraphrase
the great Met philosopher Casey Stengel: is there anybody here
that knows how to play this here relational game?

Making a column's values unique

I have an INTEGER column that I want to convert to a primary key. However,
some of the values currently in the dataset are not unique. What query will
delete any records with duplicate values of the intended index?
Many thanks!http://www.sql-server-performance.c..._duplicates.asp
http://www.sqlteam.com/item.asp?ItemID=3331
http://support.microsoft.com/kb/139444
Andrew J. Kelly SQL MVP
"Andrew Chalk" <achalk@.magnacartasoftware.com> wrote in message
news:eZld$eOkHHA.4628@.TK2MSFTNGP06.phx.gbl...
>I have an INTEGER column that I want to convert to a primary key. However,
>some of the values currently in the dataset are not unique. What query will
>delete any records with duplicate values of the intended index?
> Many thanks!
>|||Thanks! This > http://www.sqlteam.com/item.asp?ItemID=3331 did the trick.
Regards,
Andrew
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:uzNZXBPkHHA.5048@.TK2MSFTNGP04.phx.gbl...
>
> http://www.sql-server-performance.c..._duplicates.asp
> http://www.sqlteam.com/item.asp?ItemID=3331
> http://support.microsoft.com/kb/139444
>
> --
> Andrew J. Kelly SQL MVP
> "Andrew Chalk" <achalk@.magnacartasoftware.com> wrote in message
> news:eZld$eOkHHA.4628@.TK2MSFTNGP06.phx.gbl...
>|||How to remove duplicate rows from a table in SQL Server
http://support.microsoft.com/kb/139444
'Microsoft SQL Server tables should never contain duplicate rows,
nor non-unique primary keys...Duplicate PKs are a violation of
entity integrity, and should be disallowed in a relational system.'
While it is not surprising that any vetting process (should it even
exist) at Redmond would allow this nonsense to seep through, what
is particular disturbing is how it could possibly pass through
at leading institutions of learning. One can only paraphrase
the great Met philosopher Casey Stengel: is there anybody here
that knows how to play this here relational game?

Making a column's values unique

I have an INTEGER column that I want to convert to a primary key. However,
some of the values currently in the dataset are not unique. What query will
delete any records with duplicate values of the intended index?
Many thanks!http://www.sql-server-performance.com/rd_delete_duplicates.asp
http://www.sqlteam.com/item.asp?ItemID=3331
http://support.microsoft.com/kb/139444
Andrew J. Kelly SQL MVP
"Andrew Chalk" <achalk@.magnacartasoftware.com> wrote in message
news:eZld$eOkHHA.4628@.TK2MSFTNGP06.phx.gbl...
>I have an INTEGER column that I want to convert to a primary key. However,
>some of the values currently in the dataset are not unique. What query will
>delete any records with duplicate values of the intended index?
> Many thanks!
>|||Thanks! This > http://www.sqlteam.com/item.asp?ItemID=3331 did the trick.
Regards,
Andrew
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:uzNZXBPkHHA.5048@.TK2MSFTNGP04.phx.gbl...
>
> http://www.sql-server-performance.com/rd_delete_duplicates.asp
> http://www.sqlteam.com/item.asp?ItemID=3331
> http://support.microsoft.com/kb/139444
>
> --
> Andrew J. Kelly SQL MVP
> "Andrew Chalk" <achalk@.magnacartasoftware.com> wrote in message
> news:eZld$eOkHHA.4628@.TK2MSFTNGP06.phx.gbl...
>>I have an INTEGER column that I want to convert to a primary key. However,
>>some of the values currently in the dataset are not unique. What query
>>will delete any records with duplicate values of the intended index?
>> Many thanks!
>|||How to remove duplicate rows from a table in SQL Server
http://support.microsoft.com/kb/139444
'Microsoft SQL Server tables should never contain duplicate rows,
nor non-unique primary keys...Duplicate PKs are a violation of
entity integrity, and should be disallowed in a relational system.'
While it is not surprising that any vetting process (should it even
exist) at Redmond would allow this nonsense to seep through, what
is particular disturbing is how it could possibly pass through
at leading institutions of learning. One can only paraphrase
the great Met philosopher Casey Stengel: is there anybody here
that knows how to play this here relational game?

Make subtotal column widths bigger than normal columns?

The reason I say this is because a subtotal of a dollar amount will take up more space than other values. Right now, I'm forced to make all columns the same larger width because it appears to be all wrapped into 1 column width setting. I can try to change the value of the subtotal column, "matrixcolumn4", but it reverts to the other value after I press enter to apply the changes.

Sorry there is no good solution at this point. One alternative approach is to use side-by-side matrices to a subtotal column with different width, however you would need to "hide" the row headers of the second matrix.

For the next major SSRS release we are looking into significantly improved support of these scenarios.

-- Robert

Make subtotal column widths bigger than normal columns?

The reason I say this is because a subtotal of a dollar amount will take up more space than other values. Right now, I'm forced to make all columns the same larger width because it appears to be all wrapped into 1 column width setting. I can try to change the value of the subtotal column, "matrixcolumn4", but it reverts to the other value after I press enter to apply the changes.

Sorry there is no good solution at this point. One alternative approach is to use side-by-side matrices to a subtotal column with different width, however you would need to "hide" the row headers of the second matrix.

For the next major SSRS release we are looking into significantly improved support of these scenarios.

-- Robert

Monday, March 19, 2012

Make row data column data??

I need to make a report that looks like...
Statistic A Statistic B Statistic C Statistic D
----
99 07 102 91
It would be easy but the values are all in one column in the table, like...
KeyValue | StatisticCode | StatisticValue
001| A| 99
002| B| 07
003| D| 91
004| C| 102
What's the best way to do this?, we have several reports that we need to
build like this.
Thanks,
ShawnHave you tried using the matrix control?
"sysdesigner" wrote:
> I need to make a report that looks like...
> Statistic A Statistic B Statistic C Statistic D
> ----
> 99 07 102 91
>
> It would be easy but the values are all in one column in the table, like...
> KeyValue | StatisticCode | StatisticValue
> 001| A| 99
> 002| B| 07
> 003| D| 91
> 004| C| 102
>
> What's the best way to do this?, we have several reports that we need to
> build like this.
>
> Thanks,
> Shawn
>

make manual snapshots without default parameters set - how?

It seems like it is only possible to make a snapshot if I set default
values to all parameters. What I want to do is:
- The user generates a report manually after entering some parameters
- The user can decide to save this report as a snapshot by pressing on
the "New Snapshot" button
Is it right that there seems to be no way of doing this? (I'm talking
about the standard Web UI, no self-programmed web service or anything)
Thanks for any help
UrsHi,
check the linked report feature.
Elisabeth
"Urs Eichmann" wrote:
> It seems like it is only possible to make a snapshot if I set default
> values to all parameters. What I want to do is:
> - The user generates a report manually after entering some parameters
> - The user can decide to save this report as a snapshot by pressing on
> the "New Snapshot" button
> Is it right that there seems to be no way of doing this? (I'm talking
> about the standard Web UI, no self-programmed web service or anything)
> Thanks for any help
> Urs
>
>|||That's what I already do, but if I don't set all the parameters to a
default value in the linked report, I cannot make a snapshot.
Urs
Elisabeth wrote:
> Hi,
> check the linked report feature.
> Elisabeth
> "Urs Eichmann" wrote:
>
>>It seems like it is only possible to make a snapshot if I set default
>>values to all parameters. What I want to do is:
>>- The user generates a report manually after entering some parameters
>>- The user can decide to save this report as a snapshot by pressing on
>>the "New Snapshot" button
>>Is it right that there seems to be no way of doing this? (I'm talking
>>about the standard Web UI, no self-programmed web service or anything)
>>Thanks for any help
>>Urs
>>

Make Filter = False

I have a stored proc to return the main report data. I have another dataset1 to return the distinct values for my parameter. I filter the main data based on the parameter selected by user. I wanted to add 'ALL' option to the parameter drop down. I have added an UNION to the dataset1 to include this option. I now want to change my filter expresion from '=Fields!FRole.Value = Parameters!PRole.Value' to include ALL option and basically ignore the filter. Is it possibleMulti-valued parameters are not supported RS 2000. Here's a related post
with a solution that might work for you:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=ONnNRtsBEHA.3064%40tk2msftngp13.phx.gbl&rnum=2&prev=/groups%3Fq%3D%2522in%2Bclause%2522%2Bgroup:microsoft.public.sqlserver.reportingsvcs%26hl%3Den%26lr%3D%26ie%3DUTF-8%26selm%3DONnNRtsBEHA.3064%2540tk2msftngp13.phx.gbl%26rnum%3D2
Ravi Mumulla (Microsoft)
SQL Server Reporting Services
This posting is provided "AS IS" with no warranties, and confers no rights.
"vrodkar" <vrodkar@.discussions.microsoft.com> wrote in message
news:A6CBA50D-2C8F-4A97-B925-CE5DE0378347@.microsoft.com...
> I have a stored proc to return the main report data. I have another
dataset1 to return the distinct values for my parameter. I filter the main
data based on the parameter selected by user. I wanted to add 'ALL' option
to the parameter drop down. I have added an UNION to the dataset1 to include
this option. I now want to change my filter expresion from
'=Fields!FRole.Value = Parameters!PRole.Value' to include ALL
option and basically ignore the filter. Is it possible|||I'm curious on this as well as I am also trying to
implement this on a report. Has anyone founnd a
workaround?
>--Original Message--
>I have a stored proc to return the main report data. I
have another dataset1 to return the distinct values for
my parameter. I filter the main data based on the
parameter selected by user. I wanted to add 'ALL' option
to the parameter drop down. I have added an UNION to the
dataset1 to include this option. I now want to change my
filter expresion from '=Fields!FRole.Value =Parameters!PRole.Value' to include ALL option and
basically ignore the filter. Is it possible
>.
>|||Yes I use an "(All)" option in most of my reports.
It's easier if you're using queries instead of stored procedures.
In your parameter list have an item labelled "(All)" give it a Value of "%".
In your main data query have criteria or where clause using the 'LIKE' operator against the parameter, so in SQL;
SELECT * FROM tblData WHERE Country LIKE @.Country
% is the SQL wildcard character, but must be used with the like operator.
Regards
Chris McGuigan
"BiggieSize" wrote:
> I'm curious on this as well as I am also trying to
> implement this on a report. Has anyone founnd a
> workaround?
> >--Original Message--
> >I have a stored proc to return the main report data. I
> have another dataset1 to return the distinct values for
> my parameter. I filter the main data based on the
> parameter selected by user. I wanted to add 'ALL' option
> to the parameter drop down. I have added an UNION to the
> dataset1 to include this option. I now want to change my
> filter expresion from '=Fields!FRole.Value => Parameters!PRole.Value' to include ALL option and
> basically ignore the filter. Is it possible
> >.
> >
>

Monday, March 12, 2012

Make a list box not reqired.

I have a report that takes values from a list box to generate the report.
The list box gets its values from a table.
If the user does not coose anything from the list box and hits 'View Report'
It should be able to go and grab all data from the table.
How do I make RS do this?
I tried 'Allow Null Value' for that particular parameter, but it still does
not work.
Anyone knows how to do this?You could grap the value "%" as a default value of this list box and put it
in your query, nevertheless if you are usinga stored procedure you can
handle the "empty" paramters, or you use the ISNULL(Parameter,Value) in your
query. Today it´s kind of a hack to do this ;-)
HTH, Jens Süßmeyer.
--
http://www.sqlserver2005.de
--
"appu" <appu@.discussions.microsoft.com> schrieb im Newsbeitrag
news:6E985A61-49F3-4AE1-B504-29E0954EA649@.microsoft.com...
>I have a report that takes values from a list box to generate the report.
> The list box gets its values from a table.
> If the user does not coose anything from the list box and hits 'View
> Report'
> It should be able to go and grab all data from the table.
> How do I make RS do this?
> I tried 'Allow Null Value' for that particular parameter, but it still
> does
> not work.
> Anyone knows how to do this?|||Thanks! I got the answer.
I can do a union of 'all', '<select all>'
when I grab my parameters from the table.
"Jens Sü�meyer" wrote:
> You could grap the value "%" as a default value of this list box and put it
> in your query, nevertheless if you are usinga stored procedure you can
> handle the "empty" paramters, or you use the ISNULL(Parameter,Value) in your
> query. Today it´s kind of a hack to do this ;-)
> HTH, Jens Sü�meyer.
> --
> http://www.sqlserver2005.de
> --
> "appu" <appu@.discussions.microsoft.com> schrieb im Newsbeitrag
> news:6E985A61-49F3-4AE1-B504-29E0954EA649@.microsoft.com...
> >I have a report that takes values from a list box to generate the report.
> > The list box gets its values from a table.
> > If the user does not coose anything from the list box and hits 'View
> > Report'
> > It should be able to go and grab all data from the table.
> > How do I make RS do this?
> > I tried 'Allow Null Value' for that particular parameter, but it still
> > does
> > not work.
> > Anyone knows how to do this?
>
>