Showing posts with label system. Show all posts
Showing posts with label system. Show all posts

Thursday, March 22, 2012

Calculate/create Row Number without identity

How do I output a row number for a table solely for the purpose of
querying for a unique row?

In my problem, the table from a legacy system does not have a primary
key, so it limits various querying I'd like to do that identifies
uniqueness in the table.

The problem is that since I'm using DTS to simply copy the table to
SQL, I don't want to create identity rows.chrispycrunch (chrispycrunch@.gmail.com) writes:
> How do I output a row number for a table solely for the purpose of
> querying for a unique row?
> In my problem, the table from a legacy system does not have a primary
> key, so it limits various querying I'd like to do that identifies
> uniqueness in the table.
> The problem is that since I'm using DTS to simply copy the table to
> SQL, I don't want to create identity rows.

Not sure why the use of DTS would preclude the use of an IDENTITY row,
but then again I have no experience of DTS. After all, IDENTITY seems
perfect in this case.

If there really is a problem for DTS, you make a two-stepper and have
DTS to park the data in a transient table, and insert from there into
the target table.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Hi. Are you sure that the original table has no duplicates? If there
are any
duplicate, you do not have unique rows. However, assuming you want to
establish an identity for future use, you could extract the old data
row-by-row
and set a unique identity of your own construction, and maintain that
with
any new rows that get added (and make sure to have a unique index on
that
value.
All in all, the identity column is made for this.
Joe Weinstein at BEA

Monday, March 19, 2012

calculate base 32 notation from int value?

hello everyone,
i have an artificial keying system that is based upon a psuedo-randomly
changing 31 bit pattern stored in the database as an int.
the current key is stored in a table like so:
create table artificialkeys (
keyname varchar(50) primary key not null,
keyvalue int)
go
insert into artificialkeys (keyname, keyvalue)
values ('accountnumber', 1)
go
and the key is used by an entity such as this:
create table accounts (
accountnumber int primary key not null,
accountname varchar(50) not null)
go
and the key is incremented / implemented with stored procedures, such
as this:
create procedure [owner].[insert_account] (
@.accountnumber int output,
@.accountname varchar(50))
as
update artificialkeys set keyvalue = @.accountnumber = (currentvalue /
2) + ((currentvalue % 2 + ((currentvalue / 8) % 2)) % 2) * power(2, 30)
where keyname = 'accountnumber'
insert into accounts (accountnumber, accountname)
values (@.artificialkey, @.accountname)
go
this is the current setup, and it's working just fine. we get a
pseudo-random integer as our primary key with a value between 1 and
2^31 (due to the nature of the algorithm which i won't get into).
now comes the problem, and my question. these account numbers are
presented as ten digit strings to the customers (with leading zeros as
necessary), such as '0054613854', just a string version of the decimal
int value. no problem.
however we are moving to new accounting software, and there is a limit
of 6 characters for the account number, but it can still be
alphanumeric. and that brings me to my current plan. the value range,
if represented in base32 notation, would be from 1 to 4000, well within
the range the new software needs.
but this presents some problems that i thought i'd ask here. for
example, in base32 notation, some values are no longer acceptible. for
instance, i don't want someone ending up with the account number 'XXXX'
... so i'd like to impose a restriction that no more than two
consecutive digits can be above 9 in value.
also i'm not sure how i can convert the int value into a base32
representation inside the stored procedure, to be stored as a string
primary key?
the more i think about this the more it seems like i should handle this
in the middleware?
thanks for any thoughts,
jasonjason wrote:
> hello everyone,
> i have an artificial keying system that is based upon a psuedo-randomly
> changing 31 bit pattern stored in the database as an int.
> the current key is stored in a table like so:
> create table artificialkeys (
> keyname varchar(50) primary key not null,
> keyvalue int)
> go
> insert into artificialkeys (keyname, keyvalue)
> values ('accountnumber', 1)
> go
> and the key is used by an entity such as this:
> create table accounts (
> accountnumber int primary key not null,
> accountname varchar(50) not null)
> go
> and the key is incremented / implemented with stored procedures, such
> as this:
> create procedure [owner].[insert_account] (
> @.accountnumber int output,
> @.accountname varchar(50))
> as
> update artificialkeys set keyvalue = @.accountnumber = (currentvalue /
> 2) + ((currentvalue % 2 + ((currentvalue / 8) % 2)) % 2) * power(2, 30)
> where keyname = 'accountnumber'
> insert into accounts (accountnumber, accountname)
> values (@.artificialkey, @.accountname)
> go
> this is the current setup, and it's working just fine. we get a
> pseudo-random integer as our primary key with a value between 1 and
> 2^31 (due to the nature of the algorithm which i won't get into).
> now comes the problem, and my question. these account numbers are
> presented as ten digit strings to the customers (with leading zeros as
> necessary), such as '0054613854', just a string version of the decimal
> int value. no problem.
> however we are moving to new accounting software, and there is a limit
> of 6 characters for the account number, but it can still be
> alphanumeric. and that brings me to my current plan. the value range,
> if represented in base32 notation, would be from 1 to 4000, well within
> the range the new software needs.
> but this presents some problems that i thought i'd ask here. for
> example, in base32 notation, some values are no longer acceptible. for
> instance, i don't want someone ending up with the account number 'XXXX'
> ... so i'd like to impose a restriction that no more than two
> consecutive digits can be above 9 in value.
> also i'm not sure how i can convert the int value into a base32
> representation inside the stored procedure, to be stored as a string
> primary key?
> the more i think about this the more it seems like i should handle this
> in the middleware?
> thanks for any thoughts,
> jason
To eliminate the offensive words why not just exclude vowels from the
account numbers. That would only be base 31 but is generally acceptable
unless you want to start worrying about stuff like "SH1T". Maybe
another approach would be to construct a table of the smallish set of
unacceptable numbers and check against that each time.
Here's a generalised function for converting integers to a number base
defined by any character set:
CREATE FUNCTION dbo.IntToBase(@.i INTEGER, @.base_charset VARCHAR(256))
RETURNS CHAR(4)
AS
BEGIN
DECLARE @.b TINYINT, @.d1 TINYINT, @.d2 TINYINT, @.d3 TINYINT, @.d4 TINYINT
SELECT
@.b = LEN(@.base_charset),
@.d1 = FLOOR(@.i/@.b*@.b*@.b)%@.b,
@.d2 = FLOOR(@.i/@.b*@.b)%@.b,
@.d3 = FLOOR(@.i/@.b)%@.b,
@.d4 = @.i%@.b
RETURN
SUBSTRING(@.base_charset,@.d1+1,1)+
SUBSTRING(@.base_charset,@.d2+1,1)+
SUBSTRING(@.base_charset,@.d3+1,1)+
SUBSTRING(@.base_charset,@.d4+1,1)
END
GO
/* Base 31 characters */
SELECT dbo. IntToBase(1234,'0123456789BCDFGHJKLMNPQR
STVWXYZ');
/* Base 16 characters */
SELECT dbo.IntToBase(1234,'0123456789ABCDEF');
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Oops. That wasn't very well tested. Here's a correction:
CREATE FUNCTION dbo.IntToBase(@.i INTEGER, @.base_charset VARCHAR(256))
RETURNS CHAR(4)
AS
BEGIN
DECLARE @.b TINYINT, @.d1 TINYINT, @.d2 TINYINT, @.d3 TINYINT, @.d4 TINYINT
SELECT
@.b = LEN(@.base_charset),
@.d1 = FLOOR(@.i/@.b/@.b/@.b)%@.b,
@.d2 = FLOOR(@.i/@.b/@.b)%@.b,
@.d3 = FLOOR(@.i/@.b)%@.b,
@.d4 = @.i%@.b
RETURN
SUBSTRING(@.base_charset,@.d1+1,1)+
SUBSTRING(@.base_charset,@.d2+1,1)+
SUBSTRING(@.base_charset,@.d3+1,1)+
SUBSTRING(@.base_charset,@.d4+1,1)
END
GO
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||> To eliminate the offensive words why not just exclude vowels from the
> account numbers.
"And Serpent bringeth forth the vowel."
- Luke, 7-45
How about keeping a table of 'illegal' values? There can't be that many if
the string is only 4 characters long.
ML
http://milambda.blogspot.com/|||actually you're right. in fact, since the base value never goes above
2^31, the highest base32 value would be 4000, which means the first
digit never even gets to the letters. so now we're just talking about
three letter offensive words. of course we'd have to worry about
homophones too, like FUK. i'm not sure which would be easier, but i'll
consider both.|||oh wow, so i could essentially create my own notation that has no
vowels. i didn't realize that was even going to be an option, but hell
yeah, that seriously makes the offensive word thing a lot easier!
and yeah, we considered the 'leet' curse word issue, but decided that's
just too annoying to worry about. if someone gets account number SH1T,
and doesn't chuckle, then we can survive the loss.
thanks!
jason|||"jason" <iaesun@.yahoo.com> wrote in message
news:1138387792.331310.253560@.g43g2000cwa.googlegroups.com...
> actually you're right. in fact, since the base value never goes above
> 2^31, the highest base32 value would be 4000, which means the first
> digit never even gets to the letters. so now we're just talking about
> three letter offensive words. of course we'd have to worry about
> homophones too, like FUK. i'm not sure which would be easier, but i'll
> consider both.
ASS
FAG
KKK
and of course, the most offensive one of all... :-)
DBA|||FYI
Actually, the word "fuk" has that same meaning in several other languages.
Of course it's pronounced differently.
Maybe there already is a list of offensive words available somewhere.
http://en.wikipedia.org/wiki/Seven_dirty_words
ML
http://milambda.blogspot.com/|||> and of course, the most offensive one of all... :-)
> DBA
You forgot:
DEV
:)
ML
http://milambda.blogspot.com/|||hey David,
thanks, this function looks pretty versatile. i'm having an
implementation problem with it though. when i run it against the
existing list of account numbers, i'm getting a looping result. int
value 2147186326 is coming out as '0001' in base31 notation, which is
the same value that the int value 1. i thought perhaps that base31
couldn't store an int in only 4 digits, and this was a truncation
problem, so i tried to extrapolate the function to return base x
digits, but that didn't actually change the behavior, there was still a
notation wrap at 2147186326, so i'm sure i didn't modify it correctly.
just thought i'd run it by you to see if you had any ideas?
thanks again,
jason

Calculate 30/360, 30/365 DateDiff

Has anyone come across the need for performing a day difference count betwee
n
2 dates adhering to a 30/360 day convention? Is there a System Function,
Custom Function or Proc which can achieve this ?If I remember correctly that's some sort of financial/bank calculation? If
you could refresh me on the specifics of how it's done by hand I might be
able to find something for you...
"D1p4k" <dipakb@.exchange.ml.com> wrote in message
news:6DE347B3-CBEB-4F23-AC94-DF5E7B9B9484@.microsoft.com...
> Has anyone come across the need for performing a day difference count
> between
> 2 dates adhering to a 30/360 day convention? Is there a System Function,
> Custom Function or Proc which can achieve this ?|||On Tue, 26 Jul 2005 12:30:02 -0700, D1p4k wrote:

> Has anyone come across the need for performing a day difference count betw
een
> 2 dates adhering to a 30/360 day convention? Is there a System Function,
> Custom Function or Proc which can achieve this ?
See a usenet thread from Feb 2004 on this topic: http://tinyurl.com/bwglz|||30/360 = The number of accrued days is calculated on the basis of a year of
360 days and a month of 30 days. However, if the first date of an accrual
period is not the 30th or 31st, and the last date of the period is the 31st
of the month then that month is considered to have 31 days. In addition, if
the last date of the period is the last day of February, the month of
February shall not be extended to a 30-day month.
Date1= 25-oct-1996 and Date2 = 31-dec-1996 the result would be 66 days.
An Actual DateDiff would give you 67 Days|||> Date1= 25-oct-1996 and Date2 = 31-dec-1996 the result would be 66 days.
6+30+31=67
"D1p4k" <dipakb@.exchange.ml.com> wrote in message
news:5FCA9DFC-15C4-452B-AA1E-9384C55F7756@.microsoft.com...
> 30/360 = The number of accrued days is calculated on the basis of a year
> of
> 360 days and a month of 30 days. However, if the first date of an accrual
> period is not the 30th or 31st, and the last date of the period is the
> 31st
> of the month then that month is considered to have 31 days. In addition,
> if
> the last date of the period is the last day of February, the month of
> February shall not be extended to a 30-day month.
> Date1= 25-oct-1996 and Date2 = 31-dec-1996 the result would be 66 days.
> An Actual DateDiff would give you 67 Days
>|||On Tue, 26 Jul 2005 13:30:03 -0700, D1p4k wrote:

> 30/360 = The number of accrued days is calculated on the basis of a year o
f
> 360 days and a month of 30 days. However, if the first date of an accrual
> period is not the 30th or 31st, and the last date of the period is the 31s
t
> of the month then that month is considered to have 31 days. In addition, if[/color
]
^^^^^^^^^^^^^
It's not clear what you mean by "that month": do you mean that the month of
the start of the period is considered to have 31, or that the month of the
end of the period is considered to have 31?
> the last date of the period is the last day of February, the month of
> February shall not be extended to a 30-day month.
> Date1= 25-oct-1996 and Date2 = 31-dec-1996 the result would be 66 days.
> An Actual DateDiff would give you 67 Days
Tell me if this works for you.
CREATE FUNCTION dbo.DayCount30_360Days(@.d1 DATETIME, @.d2 DATETIME)
RETURNS INT
AS
BEGIN
RETURN(
SELECT DATEDIFF(MONTH, @.d1, @.d2) * 30
+ DAY(@.d2)
- DAY(@.d1)
- case when day(@.d1)>=30 AND day(@.d2) = 31 then 1 else 0 end
)
END
GO
Select dbo.DayCount30_360Days('1996-10-25','1996-12-31')
-- result: 66
Select dbo.DayCount30_360Days('1996-10-26','1996-12-31')
-- result: 65
Select dbo.DayCount30_360Days('1996-10-27','1996-12-31')
-- result: 64
Select dbo.DayCount30_360Days('1996-10-28','1996-12-31')
-- result: 63
Select dbo.DayCount30_360Days('1996-10-29','1996-12-31')
-- result: 62
Select dbo.Daycount30_360Days('1996-10-30','1996-12-31')
-- result: 60

Calcualted Cells Performance Problem

Hello,

Initially the business divided its Practices into two groups, Industrial and Functional which were maintained in the relational source system as two seperate tables. The business has decided to expand the number of practices it reports on, however changes to the relational source system has not fully been implemented. We require reporting on the Budget data now so we've created a dimension named "Practices" which follows the same dimensional structure as the "Inudstry" and "Function" dimensions except that there is an extra parent level of "Practice Type". I would like to hide this new all inclusive "Practices" dimension from end users and effectively look up the corresponding value in the Industry or Function dimension from the Budget fact table.

I have the following calculated cell which achieves the desired results but has rather slow perforamce.

CREATE CELL CALCULATION CURRENTCUBE.[Budget Functional Practice]

FOR

'({[Measures].[Budget]},

[Fiscal Date].[Fiscal].[Fiscal Mo].MEMBERS,

[Function].[Func Practice].[Func Practice Def].MEMBERS)'

AS'

(StrToMember("Measures.[" + Measures.CurrentMember.Name + "_]"),

StrToMember("[Practices].[Hierarchy].[Practice Class].&[Function Practice].&[" + [Function].[Func Practice Def].CurrentMember.Name + "]"),

[Function].[Func Practice].[All])'

I was wondering if:

a) Is a calculated cell the best solution?

b) Is there a more efficient MDX which can be used?

Thank you.

If I am understanding correctly, you have a measure called Budget_ which you want to be the budget at the All functions level. If this is correct the following scope should work and perform significantly better. All of the string and currentmember references would have been slowing things down.

SCOPE ({[Measures].[Budget]},

[Fiscal Date].[Fiscal].[Fiscal Mo].MEMBERS,

[Function].[Func Practice].[Func Practice Def].MEMBERS);

(Measures.[Budget_]) = ([Function].[Func Practice].[All], [Measures].[Budget]);

END SCOPE;

|||

Thank you for the reply Darren, I think this is a step in the right direction.

The budget fact table contains one dimension which accounts for all of our practices (this dimension is hidden from the users). What I want to be able to do is, based on a selected member from either of the visible industry practice or function practice dimensions, lookup the corresponding value in the practices dimesnsion and show the budget measure.

|||

If you're using AS 2005, you might consider an alternative approach, using many-to-many dimensions. But first (if I interpreted your scenario correctly) you would need to set up 2 "Practices" dimension security roles, 1 for users of Function and the other for users of Industry (both roles would have Visual Totals enabled). Role#1 would allow access to the "Function", and Role#2 to the "Industry" member, at the "Practice Type" level - these would also be the Default Members for the respective roles. This would ensure that Function users only access Function data and Industry users likewise. Role#1 would be denied access to the Industry dimension and Role#2 to the Function dimension.

For the many-to-many dimension modelling, there would be a bridge table (could be a named query) which maps Function dimension table rows to the Practices dimension, and a separate bridge table to map Industry. Once a measure group is created for each bridge table, 1 bridging Function and Practices and the other bridging Industry and Practices, both Function and Industry can be configured as many-to-many dimensions for the Budget measure group.

Calcualted Cells Performance Problem

Hello,

Initially the business divided its Practices into two groups, Industrial and Functional which were maintained in the relational source system as two seperate tables. The business has decided to expand the number of practices it reports on, however changes to the relational source system has not fully been implemented. We require reporting on the Budget data now so we've created a dimension named "Practices" which follows the same dimensional structure as the "Inudstry" and "Function" dimensions except that there is an extra parent level of "Practice Type". I would like to hide this new all inclusive "Practices" dimension from end users and effectively look up the corresponding value in the Industry or Function dimension from the Budget fact table.

I have the following calculated cell which achieves the desired results but has rather slow perforamce.

CREATE CELL CALCULATION CURRENTCUBE.[Budget Functional Practice]

FOR

'({[Measures].[Budget]},

[Fiscal Date].[Fiscal].[Fiscal Mo].MEMBERS,

[Function].[Func Practice].[Func Practice Def].MEMBERS)'

AS'

(StrToMember("Measures.[" + Measures.CurrentMember.Name + "_]"),

StrToMember("[Practices].[Hierarchy].[Practice Class].&[Function Practice].&[" + [Function].[Func Practice Def].CurrentMember.Name + "]"),

[Function].[Func Practice].[All])'

I was wondering if:

a) Is a calculated cell the best solution?

b) Is there a more efficient MDX which can be used?

Thank you.

If I am understanding correctly, you have a measure called Budget_ which you want to be the budget at the All functions level. If this is correct the following scope should work and perform significantly better. All of the string and currentmember references would have been slowing things down.

SCOPE ({[Measures].[Budget]},

[Fiscal Date].[Fiscal].[Fiscal Mo].MEMBERS,

[Function].[Func Practice].[Func Practice Def].MEMBERS);

(Measures.[Budget_]) = ([Function].[Func Practice].[All], [Measures].[Budget]);

END SCOPE;

|||

Thank you for the reply Darren, I think this is a step in the right direction.

The budget fact table contains one dimension which accounts for all of our practices (this dimension is hidden from the users). What I want to be able to do is, based on a selected member from either of the visible industry practice or function practice dimensions, lookup the corresponding value in the practices dimesnsion and show the budget measure.

|||

If you're using AS 2005, you might consider an alternative approach, using many-to-many dimensions. But first (if I interpreted your scenario correctly) you would need to set up 2 "Practices" dimension security roles, 1 for users of Function and the other for users of Industry (both roles would have Visual Totals enabled). Role#1 would allow access to the "Function", and Role#2 to the "Industry" member, at the "Practice Type" level - these would also be the Default Members for the respective roles. This would ensure that Function users only access Function data and Industry users likewise. Role#1 would be denied access to the Industry dimension and Role#2 to the Function dimension.

For the many-to-many dimension modelling, there would be a bridge table (could be a named query) which maps Function dimension table rows to the Practices dimension, and a separate bridge table to map Industry. Once a measure group is created for each bridge table, 1 bridging Function and Practices and the other bridging Industry and Practices, both Function and Industry can be configured as many-to-many dimensions for the Budget measure group.

Sunday, March 11, 2012

CAL License Question

I know that the number of CALs licensed to a given server is stored in some
system table because at one point I had and ran a script to provide that
information. But I either didn't keep the script or didn't name it well as I
cannot find it. Does anyone know how to query to find this information?Hi,
From Query Analyzer you can Execute
select SERVERPROPERTY('LicenseType')
select SERVERPROPERTY('NumLicenses')
FYI, CALS are not stored in any system table.
Thanks
Hari
SQL Server MVP
"RKinder" <RKinder@.discussions.microsoft.com> wrote in message
news:D22C57DA-4CA4-41CF-B9B7-EE1F8ADDED03@.microsoft.com...
> I know that the number of CALs licensed to a given server is stored in
some
> system table because at one point I had and ran a script to provide that
> information. But I either didn't keep the script or didn't name it well
as I
> cannot find it. Does anyone know how to query to find this information?|||Thank You.
For whatever reason I'm getting Disabled and Null, but I can look into that.
Thanks again.
"Hari Prasad" wrote:
> Hi,
> From Query Analyzer you can Execute
>
> select SERVERPROPERTY('LicenseType')
> select SERVERPROPERTY('NumLicenses')
> FYI, CALS are not stored in any system table.
> Thanks
> Hari
> SQL Server MVP
> "RKinder" <RKinder@.discussions.microsoft.com> wrote in message
> news:D22C57DA-4CA4-41CF-B9B7-EE1F8ADDED03@.microsoft.com...
> > I know that the number of CALs licensed to a given server is stored in
> some
> > system table because at one point I had and ran a script to provide that
> > information. But I either didn't keep the script or didn't name it well
> as I
> > cannot find it. Does anyone know how to query to find this information?
>
>|||RKinder wrote:
> Thank You.
> For whatever reason I'm getting Disabled and Null, but I can look
> into that. Thanks again.
>
I believe that's a known issue prior to SP2. What service pack are you
running?
http://support.microsoft.com/default.aspx?scid=KB;en-us;291332
--
David Gugick
Imceda Software
www.imceda.com

Wednesday, March 7, 2012

Cache Database structure (How to detect if database-design has changed..)

Hello everyone,

I have a webcontrol that uses database-structures alot, it uses the system tables in SQL to read column information from tables. To ease the load of the SQL server I have a property that stores this information in a cache and everything works fine.

I am doing some research to find if there are anyway to get information from the SQL server that the structure from a table has changed.

I want to know if a column or table has changed any values, like datatype, name, properties, etc.

Any suggestions out there ?!Sure, use a DDL trigger. Anytime something changes that you need to know about insert a record into another table (tblDDLChanged?). Then use a SqlDependancy object on the tblDDLChanged table? Although you might be able to just use a set of SqlDependancy objects to monitor the base tables themselves, but I'm not sure if it detects DDL changes or not.|||I am not able to create any triggers only able to read the tables.|||After looking at the system tables I found the answer.

You retreive when last change was done to a column in a database by the following query:

SELECT TOP 1 sysobjects.refdate FROM syscolumns INNER JOIN sysobjects ON syscolumns.id = sysobjects.id ORDER BY sysobjects.refdate DESC

Saturday, February 25, 2012

c2 auditing

Is there any way to granularise what c2 monitors? I have a system which is
generating thousands of trades and this is in turn generating a 200Mb c2
trace every 1 minute.
What kind of trading system would use C2 audit?
Linchi
"guest5" wrote:

> Is there any way to granularise what c2 monitors? I have a system which is
> generating thousands of trades and this is in turn generating a 200Mb c2
> trace every 1 minute.

c2 auditing

Is there any way to granularise what c2 monitors? I have a system which is
generating thousands of trades and this is in turn generating a 200Mb c2
trace every 1 minute.> Is there any way to granularise what c2 monitors?
That would mean it isn't a c2 trace anymore... ;-)
You can create your own server-side traces, however, and make them autostart
using sp_procoption.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"guest5" <guest5@.discussions.microsoft.com> wrote in message
news:EA8A7A35-E793-4537-B8B1-EC7AEF9C7D7D@.microsoft.com...
> Is there any way to granularise what c2 monitors? I have a system which is
> generating thousands of trades and this is in turn generating a 200Mb c2
> trace every 1 minute.|||What kind of trading system would use C2 audit?
Linchi
"guest5" wrote:

> Is there any way to granularise what c2 monitors? I have a system which is
> generating thousands of trades and this is in turn generating a 200Mb c2
> trace every 1 minute.

c2 auditing

Is there any way to granularise what c2 monitors? I have a system which is
generating thousands of trades and this is in turn generating a 200Mb c2
trace every 1 minute.> Is there any way to granularise what c2 monitors?
That would mean it isn't a c2 trace anymore... ;-)
You can create your own server-side traces, however, and make them autostart using sp_procoption.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"guest5" <guest5@.discussions.microsoft.com> wrote in message
news:EA8A7A35-E793-4537-B8B1-EC7AEF9C7D7D@.microsoft.com...
> Is there any way to granularise what c2 monitors? I have a system which is
> generating thousands of trades and this is in turn generating a 200Mb c2
> trace every 1 minute.|||What kind of trading system would use C2 audit?
Linchi
"guest5" wrote:
> Is there any way to granularise what c2 monitors? I have a system which is
> generating thousands of trades and this is in turn generating a 200Mb c2
> trace every 1 minute.

C2 Audit and BCP

I have a system that requires the functionality of c2 audit mode.
Unfortunately most the manipulations that will be taking place on this
system will be using BCP (actually they'll be using IRowsetFastLoad, but the
effect is the same).
If I use Profiler to record SQL statements each of the BCP transactions
comes out as insert bulk SQL statement.
But the audit event just contains garbage (little squares, non-printable
characters) and does not enable me to determine anything useful at all.
Has anyone else encountered this?
Has anyone been able to log BCP statements using c2 audit on SQL Server 2000
SP3a?
Does anyone know if a bug already exists for this?
Thanks.
J.T.BCP will use Native mode by default unless you specify character mode.
What exactly are you wanting to see?
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||I'd like to be able to identify that an "insert bulk" statement has
occurred.
All of the SQL Statements that are run are identified solely by the
permission event, we have to look at the text data column in Profiler to
establish what the SQL was - but when we use BCP we get a few permission
events but nothing legible in the text data column.
This isn't an issue with the functionality of BCP, it's an issue with the
audit events that profiler picks up.
What I'd like is to find the same text captured in the permissions event
(which is part of the audit set of events) as it captured by the SQL
statements events (which logs the "insert bulk" statement and identifies the
table and columns).
Thanks.
J.T.
"Kevin McDonnell [MSFT]" <kevmc@.online.microsoft.com> wrote in message
news:cLXa5U3QEHA.3960@.cpmsftngxa10.phx.gbl...
> BCP will use Native mode by default unless you specify character mode.
> What exactly are you wanting to see?
>
> Thanks,
> Kevin McDonnell
> Microsoft Corporation
> This posting is provided AS IS with no warranties, and confers no rights.
>
>

Sunday, February 19, 2012

C# application - method to import delimeted CSV to sql server table

Hi,

I'm writing a telecom billing system where it is necessary to import csv delimited files into a sql server table.

1) The csv files to import differ in column arrangement i.e SQL server table arrangement = A, B, C, D whilst CDR = - , A, -, C, D

2) The csv files are delimited via different characters i.e some are del.. by commas some by semi colons

I can import a CSV file from my application using a BULK INSERT query but only using CSV that resembles the structure of the table exactly

How can I pass a CSV to the table and state where I want each CSV column to fill a column in the SQL SERVER table

Below is how I am managing to pass a CDR to the SQL table that I have pre manufactured to resemble the structure of the SQL table Is there a way I can state which values from the CSV I want to pass to corresponding columns in the SQL table:

string conString =@."Provider=SQLOLEDB;Server=(local);Database=Billing;Uid=sa;Pwd=sa;";

for (int i = listBox1.Items.Count - 1; i >= 0; i--)

{

string strSQL;

OleDbConnection objConnection =null;

OleDbCommand objCmd =null;

objConnection =newOleDbConnection(conString);

string cdr = listBox1.GetItemText(listBox1.Items[i]);

strSQL ="BULK INSERT Campaign FROM '"+ cdr +"' WITH (FIELDTERMINATOR = ',', ROWTERMINATOR = '\n')";

OleDbDataReader objDataReader;

try

{

objConnection.Open();

objCmd =

newOleDbCommand(strSQL, objConnection);

objCmd.ExecuteNonQuery();

objCmd =

null;

objDataReader =

null;

objConnection.Close();

listBox1.Items.Remove(listBox1.Items[i]);

}

catch (Exception ex)

{

objConnection.Close();

}

objCmd =

null;

objConnection =

null;

}

Regards

Simon

It is not practical to use ExecuteNonQuery to import a CVS file because the data needs to be cleaned before insert so try the link below for a step by step guide to import the data into SQL Server. The reason it is failing is you are sending ADO.NET a data access component to perform ETL(extraction transformation and loading) task. Hope this helps.

http://www.databasejournal.com/features/mssql/article.php/3580216

|||

the code works but only for csv that mirrors the table in structure, I want to create a query that picks certain columns from the csv parses them and pastes them into a table

regards

Simon

|||

If the columns are the same that is a standard insert, picking columns is again ETL, try the CVS parser from the link below and ADO.NET is not used. Hope this helps.

http://www.heikniemi.net/hc/archives/000152.html

|||

I'll give it a go and get back to you seems a good way around it. Can I use it to iterate over each seperate line and load the values i need into a temporary dataset I.e containing a pseudo table mirroring that in sql server

Simon

c# and sql server for windows ce

hello,
i use in c# the following line:
using System.Data.SqlServerCe;
the following error is visible
"The type or namespace name 'SqlCeEngine' could not be found"
how can i fix this problem?Have you added a reference to SQLCe?
Have you installed SQL Ce on the device?
"Steiner Hubert" <nospam@.firemail2.de> wrote in message
news:O9vYtTx6DHA.1596@.TK2MSFTNGP10.phx.gbl...
> hello,
> i use in c# the following line:
> using System.Data.SqlServerCe;
> the following error is visible
> "The type or namespace name 'SqlCeEngine' could not be found"
> how can i fix this problem?
>

C# and SQL Express

hi Y'All!

I've been having quite some fun doing C#, im doing an accounting system just for the fun of it. I find C# quite user friendly (though Im using the express edition). Its not really that cryptic. Though one must be able to grasp the concept of OOP. Well, enough praise about the language, I know i wont get any freebie anyway. Just some question though.

1. Im planning to use SQL Server express as backend, right now Im using firebird and plan to change backend. What are the limitations of SQL Express edition? like can I use it in providing for example a network of 10 users with an accounting application.

2. I plan later to create a C# program (windows application) that will access a database for example in the internet, the database (SQL) residing in a server in japan? how can this be done?, They say all you have to do is define the connection string, is there a sample for this?

3. If I use SQL server express can it handle my question No. 2?

Thanks to all of you, I have learned a lot in this forum. Some of the questions and answers I could not have learned in a year or so of studies on my own.

Y'all are great!

Omar

you need to enable remote connections in order for other computers around the network to connect to it:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=802873&SiteID=1

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=687532&SiteID=1

http://support.microsoft.com/default.aspx?scid=kb;EN-US;914277

once configured, it should be ok for use!

|||

SQL Express does not support HTTP endpoints, you have to connect to it through a WAN/LAN. Other editions of SQL Server that support HTTP Endpoints can be connected through via the Internet.

Mike

Tuesday, February 14, 2012

Business Rules -> Using Lots of UDFs & Views

I am in the process of building my first "large scale" database system (after 15+ years of developing Windows Apps and Web Apps) - so I am very VERY "Green" when it comes to Database development & SQL et al.

A little context setting: I am building a multi-tier Statistical Analysis & Reporting system where the "end product" will be Reports created in Reporting Services. There are a ton of business rules that I am implementing in a Business Logic Tier (hidden from the "end user" by a Data Access Tier) comprised of SQL in the form of UDFs (scalar) and Views.

The question: I have been reading that UDFs cause a performance hit compared to things like in-line functions. Alot of the Rules (implemented as Scalar UDFs) build on each other so that the output of UDF #1 is used as input to UDF #2.

So far I am implementing the Business Logic as a hierarchy of Views (7 Views to be exact) with each view implementing multiple Rules; each Rule basically a Scalar UDF. Below is an example of what I am doing:

Example

View #1 -> Select A, B, C, funcX1(A) as ValueX1, funcY1(B, C) as ValueY1 FROM someView

Then

View #2 -> Select A, B, C, ValueX1, ValueY1, funcX2 (ValueX1) as ValueX2, funcY2(ValueY2) as ValueY2 FROM View#1

Currently I have a hierarchy of 7 views that each use UDFs to implement the Business Rules, where the value calculated from a UDF in one View is used as input to UDF in a View further down the Hierarchy.

Is there a better way of implementing all of the Rules instead of using multiple Views with a bunch of UDFs?

The "end product" dataset is then exposed as a Stored Procedure to the reports in Reporting Services.

Any help would be GREATLY appreciated.

Thanks!
- marty

You can make View #1 -> Select A, B, C, funcX1(A) as ValueX1, funcY1(B, C) as ValueY1 FROM someView
and

View #2 -> Select A, B, C, ValueX1, ValueY1, funcX2 (ValueX1) as ValueX2, funcY2(ValueY2) as ValueY2 FROM View#1

as indexed views (if your func's are deterministic ) that will improve performance

see Books Online (look for "indexed views")

To the other part I see a reccurence in building your views; another new feature of SQL 2005 is "common table expressions" that can permit creating recursive queries (look Books Online for "common table expressions" )

|||

Hi!

Well it seems you already got an answer, but here something I would like to add:

For business rules:

use 3NF design (or dw design), use constraints (fk, check constraints, uk/indexes) whenever possible

and use stored procedures as access layer (when not using dw design).

With stored procedures as layer between you highly control access and have freedom to change

your implementation (table design) behind the scenes without breaking code.

This comes escpecially useful, when you have to solve performance problems!

|||You guys Rock!

Using a CTE works like a charm! Using a CTE in a View allows me to use the output of 1 function as input to a 2nd function within the same View.

I am I'm now looking into Indexed Views to see about improving the performance of my Business Rules.

Thanks Again!

business process logic in stored procedures

Hi All,
I've always tried to think of and use sql as being a tool to quickly
retrieve / update relevant data, and let other parts of a system handle
the decisions as to what needs to be done to the data. However I keep
coming across (and sometimes find myself creating) the situation where
there are massive stored procedures which will have several different
statements, pulling data from loads of tables and updating others based
on some business logic.
First question: is this a bad thing?
as I see it this has the advantage that updates can be expressed as a
function to be applied over a whole table, making the process much
faster than if the data was changed in a business layer, then
propogated to the database. However the "code" is hard for someone else
to understand, and hard to re-use/improve. I often find that processes
which would be modelled with quite a large framework of objects are
condensed down into a large stored procedure, such that to anyone else
looking at it will just see a mass of update insert and selects with no
idea why.
Second question: when to do it?
I have found that at times it's unaviodable, either for performance or
simply the ease of access to all the data that I need to use a stored
proc, does anyone have any rules of thumb as to when it's a good/bad
idea?
Third question: what are the alternatives?
I'd hope that there are other ways to get around the problems that
people are solving using sql, does anyone have any links/suggestions of
how to approach things that people would often resort to sql for, using
more maintainable methods?
I could probably rattle on for days on this issue, but I'm hoping maybe
people will be able to suggest some best practice about this.
Cheers
WillWill
1),2)
I remember some times ago it was discussion about this subject and some
people say that they put the business logic in the stored procedure and
some people say they do not but only code/dll....
I have been praticipate in some projects where we put all login in to
stored procedure and it was relaible/readable and worder very good in terms
of perfomance as well
So the answer will be it depends on YOUR project's business logic and sure
if you can test 'somehow' and make the right decision
3) Well if you develop multi tier application the question is where to put
BL in data layer (dll that access to the database) or directly to stored
procedures
Again , I have seen many projects where people (including me) put the logic
into SP and some projects where people put the BL (including me) in the
code, so it is really DEPENDS on many things.
If you are lucky and Erlan ( and many others here at forum) jump in , it is
interesting to see what does he suggest ?
"Will" <william_pegg@.yahoo.co.uk> wrote in message
news:1144324357.527781.15400@.e56g2000cwe.googlegroups.com...
> Hi All,
> I've always tried to think of and use sql as being a tool to quickly
> retrieve / update relevant data, and let other parts of a system handle
> the decisions as to what needs to be done to the data. However I keep
> coming across (and sometimes find myself creating) the situation where
> there are massive stored procedures which will have several different
> statements, pulling data from loads of tables and updating others based
> on some business logic.
> First question: is this a bad thing?
> as I see it this has the advantage that updates can be expressed as a
> function to be applied over a whole table, making the process much
> faster than if the data was changed in a business layer, then
> propogated to the database. However the "code" is hard for someone else
> to understand, and hard to re-use/improve. I often find that processes
> which would be modelled with quite a large framework of objects are
> condensed down into a large stored procedure, such that to anyone else
> looking at it will just see a mass of update insert and selects with no
> idea why.
> Second question: when to do it?
> I have found that at times it's unaviodable, either for performance or
> simply the ease of access to all the data that I need to use a stored
> proc, does anyone have any rules of thumb as to when it's a good/bad
> idea?
> Third question: what are the alternatives?
> I'd hope that there are other ways to get around the problems that
> people are solving using sql, does anyone have any links/suggestions of
> how to approach things that people would often resort to sql for, using
> more maintainable methods?
> I could probably rattle on for days on this issue, but I'm hoping maybe
> people will be able to suggest some best practice about this.
> Cheers
> Will
>

Sunday, February 12, 2012

Business Intelligence Studio disappeared

Hi I had the Business Intelligence Studio for SQL Server 2005 installed and
then I went and installed VS Team System. My Business Intelligence Studio
seems to have disappeared and when I fire up Visual Studio I get errors that
it can't load various packages e.g. Report Designer, which I think are
related to Business Intelligence Studio. I have tried reinstalling SQL
server tools but it thinks everything is installed. Does anyone have any
ideas, Chris.It's actually the same program. When you open and create a new project, you
will see that BI is still there along with all the other VS options in VB,
C#, etc
--
Regards,
Jamie
"Fresno Bob" wrote:
> Hi I had the Business Intelligence Studio for SQL Server 2005 installed and
> then I went and installed VS Team System. My Business Intelligence Studio
> seems to have disappeared and when I fire up Visual Studio I get errors that
> it can't load various packages e.g. Report Designer, which I think are
> related to Business Intelligence Studio. I have tried reinstalling SQL
> server tools but it thinks everything is installed. Does anyone have any
> ideas, Chris.
>
>|||Sorry, I missed part of your thread from reading too quickly. If you have
the developer version of SQL Server 2005 installed, you should be able to put
the disk in and run a repair.
--
Regards,
Jamie
"Fresno Bob" wrote:
> Hi I had the Business Intelligence Studio for SQL Server 2005 installed and
> then I went and installed VS Team System. My Business Intelligence Studio
> seems to have disappeared and when I fire up Visual Studio I get errors that
> it can't load various packages e.g. Report Designer, which I think are
> related to Business Intelligence Studio. I have tried reinstalling SQL
> server tools but it thinks everything is installed. Does anyone have any
> ideas, Chris.
>
>

Business Intelligence Studio disappeared

Hi I had the Business Intelligence Studio for SQL Server 2005 installed and
then I went and installed VS Team System. My Business Intelligence Studio
seems to have disappeared and when I fire up Visual Studio I get errors that
it can't load various packages e.g. Report Designer, which I think are
related to Business Intelligence Studio. I have tried reinstalling SQL
server tools but it thinks everything is installed. Does anyone have any
ideas, Chris.It's actually the same program. When you open and create a new project, you
will see that BI is still there along with all the other VS options in VB,
C#, etc
--
Regards,
Jamie
"Fresno Bob" wrote:

> Hi I had the Business Intelligence Studio for SQL Server 2005 installed an
d
> then I went and installed VS Team System. My Business Intelligence Studio
> seems to have disappeared and when I fire up Visual Studio I get errors th
at
> it can't load various packages e.g. Report Designer, which I think are
> related to Business Intelligence Studio. I have tried reinstalling SQL
> server tools but it thinks everything is installed. Does anyone have any
> ideas, Chris.
>
>|||Sorry, I missed part of your thread from reading too quickly. If you have
the developer version of SQL Server 2005 installed, you should be able to pu
t
the disk in and run a repair.
--
Regards,
Jamie
"Fresno Bob" wrote:

> Hi I had the Business Intelligence Studio for SQL Server 2005 installed an
d
> then I went and installed VS Team System. My Business Intelligence Studio
> seems to have disappeared and when I fire up Visual Studio I get errors th
at
> it can't load various packages e.g. Report Designer, which I think are
> related to Business Intelligence Studio. I have tried reinstalling SQL
> server tools but it thinks everything is installed. Does anyone have any
> ideas, Chris.
>
>