Thursday, March 22, 2012
Database Field showing as zero in report footer but works in group footer
Problem:
Database field shows correct value and works in formulas properly in group footer.
In Report footer this same database field shows as zero and therefore other formulas in the report footer do not calculate correctly.
Any solutions?Please. Any help would be greatly appreciated. I'm kind of in a time crunch.
I'm not sure why a database field would show the value in the group footer and come up zero in the report footer.
Any ideas??|||Sorry, don't know why either - the report footer always shows the final database record for me!
I have read of other people having this problem, and I believe that assigning the fiele to a shared variable has allowed the value to be used.|||I gave it a variable and now it works. How weird is that?!
Thanks for your help!sql
Wednesday, March 21, 2012
Database error
i am getting this error messages relzated to "sp_configure"
can anyone please give me a solution for this
Critical --X-- 6:27:37 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3234 DBSPI40-1: Unable to fetch data from table 'sysdatabases' [Attempt to fetch on unopened cursor. (19525)].
Critical --X-- 6:27:36 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3233 DBSPI40-1: Unable to fetch data from table 'sysdatabases' [Attempt to fetch on unopened cursor. (19525)].
Critical 1 --X--X- 4:41:38 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3025 DBSPI40-1: Unable to fetch data from table 'spt_monitor' [Attempt to fetch on unopened cursor. (19525)].
Critical 4 --X--X- 3:44:43 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3227 DBSPI40-1: Unable to fetch data from table 'sysprocesses' [Attempt to fetch on unopened cursor. (19525)].
Critical 3 --X--X- 3:44:43 AM 20/11/07 VSS HP DBSPI DBSPI vss:metric3025 DBSPI40-1: Unable to fetch data from table 'sp_configure 'max degree of parallelism'' [Attempt to fetch on unopened cursor. (19525)].
Thanks & Regards
ferozWhere are you seeing these error messages? in the Windows Event Log?sql
Saturday, February 25, 2012
Database design question
scenario:
TABLE: RULE
--
RULE_ID STATE PRODUCT MARKET
--
R1 ALL ALL ALL
R2 NY DOL NULL
R2 CA NULL NULL
In front-end application we need to know what rule to use based on what
state, product and market we are using at the moment.
Selection Criteria for the rules might expand (ex. in the future we
might add EMPLOYEE column to the RULE table)
In this set-up if I need to know what rule to use for the state OF CA
than my query would be as following:
SELECT RULE_ID
WHERE STATE='CA' and PRODUCT is NULL and MARKET is null
That would return me the R3.
For all others default with ALL values would be used.
"ALL" is not a valid state so there is some hardcoding required to
return this default record.
Is it better to repeat all states and all products and all markets in
the RULE table?
Is there way to avoid changing table structure every time I add new
criteria for selecting the rules?
I hope I was clear enough...
Thanks in advance.Hi
It is not clear why you are checking PRODUCT and MARKET if you want a rule
applicable to 'CA' And why you ignore R1 for CA?
Rule Type Values
R1 State All
R1 Product All
R1 Market All
R2 State CA
R2 State NY
R2 Product DOL
You could also make Type a lookup table and use the key value in your table.
Your queries will be simplified if you do not have the 'All' option. To keep
your existing code and use the new table you could create a view
John
"unklevo" wrote:
> I am trying to find more elegant design solution for the following
> scenario:
>
> TABLE: RULE
> --
> RULE_ID STATE PRODUCT MARKET
> --
> R1 ALL ALL ALL
> R2 NY DOL NULL
> R2 CA NULL NULL
>
> In front-end application we need to know what rule to use based on what
> state, product and market we are using at the moment.
> Selection Criteria for the rules might expand (ex. in the future we
> might add EMPLOYEE column to the RULE table)
> In this set-up if I need to know what rule to use for the state OF CA
> than my query would be as following:
> SELECT RULE_ID
> WHERE STATE='CA' and PRODUCT is NULL and MARKET is null
> That would return me the R3.
> For all others default with ALL values would be used.
>
> "ALL" is not a valid state so there is some hardcoding required to
> return this default record.
> Is it better to repeat all states and all products and all markets in
> the RULE table?
> Is there way to avoid changing table structure every time I add new
> criteria for selecting the rules?
> I hope I was clear enough...
> Thanks in advance.
>|||Thank you for your response John.
I made a mistake in my table data.
It should look like this.
TABLE: RULE
--
RULE_ID STATE PRODUCT MARKET
--
R1 ALL ALL ALL
R2 NY DOL NULL
R3 CA NULL NULL
The reason I am checking for MARKET and PRODUCT for 'CA' is that if I
fill in the product for R3 record
R3 CA DOL NULL
than using just a state='CA' is not sufficient.
All 'CA' accounts that have product other than 'DOL' will use rule R1
but accounts with state='CA' and PRODUCT='DOL' will use R3.
In set-up that you are offering can you give me an example of your
query where you want to find rule for state='NY' and product='DOL'and
market='A'
Thanks,
Igor.|||Hi
One Way:
SELECT DISTINCT R.Rule
FROM MyRules R
WHERE EXISTS ( SELECT * FROM MyRules S WHERE S.Type = 'State' AND
S.Value = 'CA' AND R.Rule = S.Rule )
AND EXISTS ( SELECT * FROM MyRules P WHERE P.Type = 'Product' AND
P.Value = 'DOL' AND R.Rule = P.Rule )
AND EXISTS ( SELECT * FROM MyRules M WHERE M.Type = 'Market' AND
M.Value = 'A' AND R.Rule = P.Rule )
Or
CREATE VIEW MyRulesView AS
SELECT R.Rule, S.Value AS State, P.Value AS Product, M.Value AS Market
FROM MyRules R
FULL OUTER JOIN MyRules S ON R.Rule = S.Rule AND S.Type = 'State'
FULL OUTER JOIN MyRules P ON R.Rule = P.Rule AND P.Type = 'Product'
FULL OUTER JOIN MyRules M ON R.Rule = M.Rule AND P.Type = 'Market'
SELECT Rule, State, Product, Market
FROM MyRulesView
WHERE State = 'CA'
AND Product = 'DOL'
AND Market = 'A'
John|||Can you explain in terms of a logical data model why you think that
state, product and market are values and not attributes that take on
values. See the problem? This is an EAV design, which is always a
disaster.
Database design question
scenario:
TABLE: RULE
--
RULE_ID STATE PRODUCT MARKET
--
R1 ALL ALL ALL
R2 NY DOL NULL
R2 CA NULL NULL
In front-end application we need to know what rule to use based on what
state, product and market we are using at the moment.
Selection Criteria for the rules might expand (ex. in the future we
might add EMPLOYEE column to the RULE table)
In this set-up if I need to know what rule to use for the state OF CA
than my query would be as following:
SELECT RULE_ID
WHERE STATE='CA' and PRODUCT is NULL and MARKET is null
That would return me the R3.
For all others default with ALL values would be used.
"ALL" is not a valid state so there is some hardcoding required to
return this default record.
Is it better to repeat all states and all products and all markets in
the RULE table?
Is there way to avoid changing table structure every time I add new
criteria for selecting the rules?
I hope I was clear enough...
Thanks in advance.This is a SQL version of a decision table with NULL as the "don't care
token". I would replace 'ALL' with NULL and write the query as:
SELECT rule_id
FROM Rules
WHERE state = COALESCE (@.mystate, state)
AND product_code = COALESCE (@.myproduct, product_code)
AND market = COALESCE(@.mymarket, market);
If more than one rule applies, you will get all of them back. You will
always have R1 in the set. If you must pick one and only one rule,
with R1 as the default, then use:
SELECT MAX (rule_id)
FROM Rules
WHERE state = COALESCE (@.mystate, state)
AND product_code = COALESCE (@.myproduct, product_code)
AND market = COALESCE(@.mymarket, market)
HAVING COUNT(*) = 2;
This means that you have one rule and R1.|||Celko,
Thank you for offering this solution.
I think that this is more elegant than the one I and John were
offering.
I will try to implement it.
Thanks again,
Igor.
Friday, February 17, 2012
Database creation using VB.NET Code
I think its silly question but i expect some solution .
Is there any way to create sql sever database by using VB.NET code ? I have to create database,tables,sps and also transfer the data from one database to newly created database.
Please, if somebody have some solution then guide me in detail.
Thanks in adv.If the database you need to create is a copy of some fixed database, you can create SSIS package, and then run it from VB.NET code.
If you just need to create a database from scratch, use SMO. See Books Online, and if you need help consult SMO/DMO forum:
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=88&SiteID=1
|||
Hi,
I am trying to create a copy of some fixed database. I am wondering how creating a SSIS package will help.Is there any code for making this database replication?
Thank You!
|||Partially it depends on exactly what your problem is. If you just want to take a database from one server and move it to another, why not issue a backup, copy, and restore using 3 SSIS tasks? You'll need to fix up any SQL Server users, but that could be scripted as well as adding any missing logins.
Another alternative if you can take the database offline, is to detach the database, copy the database files directly, and then reattach on both servers. Might be a bit faster but requires some down-time.
There's also a Transfer SQL Server Objects task if more approrpriate to your needs which might wrap most of the stuff up into one task.
If you just want to sync one database to another while they are both online, then hopefully your database is structured to do that or you'll have to truncate or delete the records from the tables in the destination and then create data flow tasks for each level of referential integrity to move the data.
You could also look at SQL Server replication or SQL Server Mirroring.
|||Basically, what I am trying to do is within the same server, i want to create a copy of an existing database. This copy will be used for a different purpose.
|||Backup and restore to a new name WITH MOVE sounds like the easiest. On a single server you could do it all in one SQL Task or break it into two, you won't have to fix users or add logins either.|||Is there any sample code where I can look at written in vb.net?
|||
Just standard .Net code. You'll likely have better luck over in the VB or C# forums for help with the code and in the Transact SQL forums for assistance with the SQL. Below is a fictionalized example. You might add a DROP DATABASE, you may want to kill off connections, etc. It would just be additional SQL in the code below. Change the CommandTimeout based on how long you expect it to restore (in seconds) and then maybe double it. Below is assuming it takes 30ish minutes to backup and restore.
Imports System.Text
Module Module1
Sub Main()
Using cn As New SqlClient.SqlConnection(My.Settings.Connection)
cn.Open()
Dim sql As New StringBuilder
sql.AppendLine("BACKUP DATABASE [myDatabase] TO DISK='C:\mypath\myfile.BAK';")
sql.AppendLine("RESTORE DATABASE [myDatabaseNEW] FROM DISK='C:\mypath\myfile.BAK WITH MOVE myDatabase_Data TO 'C:\mydatapath\myDatabaseNEW.MDF', MOVE myDatabase_Log TO 'C:\mydatapath\myDatabaseNEW.ldf'")
Using cmd As New SqlClient.SqlCommand(sql.ToString, cn)
cmd.CommandTimeout = 1800
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
End Module
|||
Hi,
I get an error saying that 'myDatabase.mdf' cannot be overwritten because it us being used by database 'myDatabase'
|||Your WITH MOVE isn't working, make sure the files listed are different than the files of the original database.
Such as myDatabaseNew.mdf not myDatabase.mdf.
|||
I found where the mistake was. Instead of using WITH MOVE 'myDatabase' I wrote it as WITH MOVE 'myDatabaseNew'. This was the reason for the error.
Its working well now.
Thanks !
|||Just an alternate suggestion - there is a Transfer Database task in SSIS that automates much of this.
Database creation using VB.NET Code
I think its silly question but i expect some solution .
Is there any way to create sql sever database by using VB.NET code ? I have to create database,tables,sps and also transfer the data from one database to newly created database.
Please, if somebody have some solution then guide me in detail.
Thanks in adv.
If the database you need to create is a copy of some fixed database, you can create SSIS package, and then run it from VB.NET code.
If you just need to create a database from scratch, use SMO. See Books Online, and if you need help consult SMO/DMO forum:
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=88&SiteID=1
|||
Hi,
I am trying to create a copy of some fixed database. I am wondering how creating a SSIS package will help.Is there any code for making this database replication?
Thank You!
|||Partially it depends on exactly what your problem is. If you just want to take a database from one server and move it to another, why not issue a backup, copy, and restore using 3 SSIS tasks? You'll need to fix up any SQL Server users, but that could be scripted as well as adding any missing logins.
Another alternative if you can take the database offline, is to detach the database, copy the database files directly, and then reattach on both servers. Might be a bit faster but requires some down-time.
There's also a Transfer SQL Server Objects task if more approrpriate to your needs which might wrap most of the stuff up into one task.
If you just want to sync one database to another while they are both online, then hopefully your database is structured to do that or you'll have to truncate or delete the records from the tables in the destination and then create data flow tasks for each level of referential integrity to move the data.
You could also look at SQL Server replication or SQL Server Mirroring.
|||Basically, what I am trying to do is within the same server, i want to create a copy of an existing database. This copy will be used for a different purpose.
|||Backup and restore to a new name WITH MOVE sounds like the easiest. On a single server you could do it all in one SQL Task or break it into two, you won't have to fix users or add logins either.|||Is there any sample code where I can look at written in vb.net?
|||
Just standard .Net code. You'll likely have better luck over in the VB or C# forums for help with the code and in the Transact SQL forums for assistance with the SQL. Below is a fictionalized example. You might add a DROP DATABASE, you may want to kill off connections, etc. It would just be additional SQL in the code below. Change the CommandTimeout based on how long you expect it to restore (in seconds) and then maybe double it. Below is assuming it takes 30ish minutes to backup and restore.
Imports System.Text
Module Module1
Sub Main()
Using cn As New SqlClient.SqlConnection(My.Settings.Connection)
cn.Open()
Dim sql As New StringBuilder
sql.AppendLine("BACKUP DATABASE [myDatabase] TO DISK='C:\mypath\myfile.BAK';")
sql.AppendLine("RESTORE DATABASE [myDatabaseNEW] FROM DISK='C:\mypath\myfile.BAK WITH MOVE myDatabase_Data TO 'C:\mydatapath\myDatabaseNEW.MDF', MOVE myDatabase_Log TO 'C:\mydatapath\myDatabaseNEW.ldf'")
Using cmd As New SqlClient.SqlCommand(sql.ToString, cn)
cmd.CommandTimeout = 1800
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
End Module
|||
Hi,
I get an error saying that 'myDatabase.mdf' cannot be overwritten because it us being used by database 'myDatabase'
|||Your WITH MOVE isn't working, make sure the files listed are different than the files of the original database.
Such as myDatabaseNew.mdf not myDatabase.mdf.
|||
I found where the mistake was. Instead of using WITH MOVE 'myDatabase' I wrote it as WITH MOVE 'myDatabaseNew'. This was the reason for the error.
Its working well now.
Thanks !
|||Just an alternate suggestion - there is a Transfer Database task in SSIS that automates much of this.