Cumulative Distributive Functions For Normal And Binomial
Jan 24, 2008Hi,
How do we go about creating some user defined functions for cumulative distributive functions for normal and binomial distributions?
Thank you.
Hi,
How do we go about creating some user defined functions for cumulative distributive functions for normal and binomial distributions?
Thank you.
I am here with a doubt in MDX. I want to calculate the Binomial Distribution for one of the Measure in my cube. The requirement is to create a new calculated measure in the cube which calculates the binomial distribution for an inbuilt measure.I am using SSAS 2012 Standard Edition.
View 6 Replies View RelatedI was playing around with the new SQL 2005 CLR functionality andremembered this discussion that I had with Erland Sommarskog concerningperformance of scalar UDFs some time ago (See "Calling sp_oa* infunction" in this newsgroup). In that discussion, Erland made thefollowing comment about UDFs in SQL 2005:[color=blue][color=green]>>The good news is that in SQL 2005, Microsoft has addressed several of[/color][/color]these issues, and the cost of a UDF is not as severe there. In fact fora complex expression, a UDF in written a CLR language may be fasterthanthe corresponding expression using built-in T-SQL functions.<<I thought the I would put this to the test using some of the same SQLas before, but adding a simple scalar CLR UDF into the mix. The testinvolved querying a simple table with about 300,000 rows. Thescenarios are as follows:(A) Use a simple CASE function to calculate a column(B) Use a simple CASE function to calculate a column and as a criterionin the WHERE clause(C) Use a scalar UDF to calculate a column(D) Use a scalar UDF to calculate a column and as a criterion in theWHERE clause(E) Use a scalar CLR UDF to calculate a column(F) Use a scalar CLR UDF to calculate a column and as a criterion inthe WHERE clauseA sample of the results is as follows (time in milliseconds):(295310 row(s) affected)A: 1563(150003 row(s) affected)B: 906(295310 row(s) affected)C: 2703(150003 row(s) affected)D: 2533(295310 row(s) affected)E: 2060(150003 row(s) affected)F: 2190The scalar CLR UDF function was significantly faster than the classicscalar UDF, even for this very simple function. Perhaps a more complexfunction would have shown even a greater difference. Based on this, Imust conclude that Erland was right. Of course, it's still faster tostick with basic built-in functions like CASE.In another test, I decided to run some queries to compare built-inaggregates vs. a couple of simple CLR aggregates as follows:(G) Calculate averages by group using the built-in AVG aggregate(H) Calculate averages by group using a CLR aggregate that similatesthe built-in AVG aggregate(I) Calculate a "trimmed" average by group (average excluding highestand lowest values) using built-in aggregates(J) Calculate a "trimmed" average by group using a CLR aggregatespecially designed for this purposeA sample of the results is as follows (time in milliseconds):(59 row(s) affected)G: 313(59 row(s) affected)H: 890(59 row(s) affected)I: 216(59 row(s) affected)J: 846It seems that the CLR aggregates came with a significant performancepenalty over the built-in aggregates. Perhaps they would pay off if Iwere attempting a very complex type of aggregation. However, at thispoint I'm going to shy away from using these unless I can't find a wayto do the calculation with standard SQL.In a way, I'm happy that basic SQL still seems to be the fastest way toget things done. With the addition of the new CLR functionality, Isuspect that MS may be giving us developers enough rope to comfortablyhang ourselves if we're not careful.Bill E.Hollywood, FL------------------------------------------------------------------------- table TestAssignment, about 300,000 rowsCREATE TABLE [dbo].[TestAssignment]([TestAssignmentID] [int] NOT NULL,[ProductID] [int] NULL,[PercentPassed] [int] NULL,CONSTRAINT [PK_TestAssignment] PRIMARY KEY CLUSTERED([TestAssignmentID] ASC)--Scalar UDF in SQLCREATE FUNCTION [dbo].[fnIsEven](@intValue int)RETURNS bitASBEGINDeclare @bitReturnValue bitIf @intValue % 2 = 0Set @bitReturnValue=1ElseSet @bitReturnValue=0RETURN @bitReturnValueEND--Scalar CLR UDF/*using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;public partial class UserDefinedFunctions{[Microsoft.SqlServer.Server.SqlFunction(IsDetermini stic=true,IsPrecise=true)]public static SqlBoolean IsEven(SqlInt32 value){if(value % 2 == 0){return true;}else{return false;}}};*/--Test #1--Scenario A - Query with calculated column--SELECT TestAssignmentID,CASE WHEN TestAssignmentID % 2=0 THEN 1 ELSE 0 END ASCalcColumnFROM TestAssignment--Scenario B - Query with calculated column as criterion--SELECT TestAssignmentID,CASE WHEN TestAssignmentID % 2=0 THEN 1 ELSE 0 END ASCalcColumnFROM TestAssignmentWHERE CASE WHEN TestAssignmentID % 2=0 THEN 1 ELSE 0 END=1--Scenario C - Query using scalar UDF--SELECT TestAssignmentID,dbo.fnIsEven(TestAssignmentID) AS CalcColumnFROM TestAssignment--Scenario D - Query using scalar UDF as crierion--SELECT TestAssignmentID,dbo.fnIsEven(TestAssignmentID) AS CalcColumnFROM TestAssignmentWHERE dbo.fnIsEven(TestAssignmentID)=1--Scenario E - Query using CLR scalar UDF--SELECT TestAssignmentID,dbo.fnIsEven_CLR(TestAssignmentID) AS CalcColumnFROM TestAssignment--Scenario F - Query using CLR scalar UDF as crierion--SELECT TestAssignmentID,dbo.fnIsEven_CLR(TestAssignmentID) AS CalcColumnFROM TestAssignmentWHERE dbo.fnIsEven(TestAssignmentID)=1--CLR Aggregate functions/*using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;[Serializable][Microsoft.SqlServer.Server.SqlUserDefinedAggregate (Format.Native)]public struct Avg{public void Init(){this.numValues = 0;this.totalValue = 0;}public void Accumulate(SqlDouble Value){if (!Value.IsNull){this.numValues++;this.totalValue += Value;}}public void Merge(Avg Group){if (Group.numValues > 0){this.numValues += Group.numValues;this.totalValue += Group.totalValue;}}public SqlDouble Terminate(){if (numValues == 0){return SqlDouble.Null;}else{return (this.totalValue / this.numValues);}}// private accumulatorsprivate int numValues;private SqlDouble totalValue;}[Serializable][Microsoft.SqlServer.Server.SqlUserDefinedAggregate (Format.Native)]public struct TrimmedAvg{public void Init(){this.numValues = 0;this.totalValue = 0;this.minValue = SqlDouble.MaxValue;this.maxValue = SqlDouble.MinValue;}public void Accumulate(SqlDouble Value){if (!Value.IsNull){this.numValues++;this.totalValue += Value;if (Value < this.minValue)this.minValue = Value;if (Value > this.maxValue)this.maxValue = Value;}}public void Merge(TrimmedAvg Group){if (Group.numValues > 0){this.numValues += Group.numValues;this.totalValue += Group.totalValue;if (Group.minValue < this.minValue)this.minValue = Group.minValue;if (Group.maxValue > this.maxValue)this.maxValue = Group.maxValue;}}public SqlDouble Terminate(){if (this.numValues < 3)return SqlDouble.Null;else{this.numValues -= 2;this.totalValue -= this.minValue;this.totalValue -= this.maxValue;return (this.totalValue / this.numValues);}}// private accumulatorsprivate int numValues;private SqlDouble totalValue;private SqlDouble minValue;private SqlDouble maxValue;}*/--Test #2--Scenario G - Average Query using built-in aggregate--SELECT ProductID, Avg(Cast(PercentPassed AS float))FROM TestAssignmentGROUP BY ProductIDORDER BY ProductID--Scenario H - Average Query using CLR aggregate--SELECT ProductID, dbo.Avg_CLR(Cast(PercentPassed AS float)) AS AverageFROM TestAssignmentGROUP BY ProductIDORDER BY ProductID--Scenario I - Trimmed Average Query using built in aggregates/setoperations--SELECT A.ProductID,CaseWhen B.CountValues<3 Then NullElse Cast(A.Total-B.MaxValue-B.MinValue ASfloat)/Cast(B.CountValues-2 As float)End AS AverageFROM(SELECT ProductID, Sum(PercentPassed) AS TotalFROM TestAssignmentGROUP BY ProductID) ALEFT JOIN(SELECT ProductID,Max(PercentPassed) AS MaxValue,Min(PercentPassed) AS MinValue,Count(*) AS CountValuesFROM TestAssignmentWHERE PercentPassed Is Not NullGROUP BY ProductID) BON A.ProductID=B.ProductIDORDER BY A.ProductID--Scenario J - Trimmed Average Query using CLR aggregate--SELECT ProductID, dbo.TrimmedAvg_CLR(Cast(PercentPassed AS real)) ASAverageFROM TestAssignmentGROUP BY ProductIDORDER BY ProductID
View 9 Replies View RelatedHi. Sorry if I am asking a stupid question since I am an absolutely beginnerin SQL Server. Here is the question . . .About 13 hours ago, I got my SQL Server 2000 to index a table which has 104million records. At first the CPU usage was high. But after an hour or two,the process has seemed dead and the Enterprise Manager has had no response.The CPU usuage dropped to zero and has been jumping between 0 to 5%. Theharddisk indicator has been blinking at a rate of roughly three times pertwo seconds.Is this normal? Has anyone got any idea how long the process would take? Ihave assigned 1.8GB of RAM to the SQL service and is currently taking upabout 1GB.
View 7 Replies View RelatedImpossible to connect to my mssql 2000 database
web.config connexion string >>>
<add key="DataSourceSql" value="Initial Catalog=angiras;Data Source=localhost;Uid=sa;Pwd=;" />
or
<add key="DataSourceSql" value="Initial Catalog=angiras;Data Source=localhost;" />
connexion code >>>
Private ConnexionSQL As SqlConnection
Public Sub OpenConnexionSQL()
ConnexionSQL = New SqlConnection(ConfigurationSettings.AppSettings("DataSourceSql").ToString)
ConnexionSQL.Open()
End Sub
when I try >>>
OpenConnexionSQL
I get an error
any idea ?
thank you
Hi guys, I've been thinking about this problem now for some time but somehow I don't know if my "solution" for it is right. I'd like to read your opinion.
There is a Capital table with Capital_Nr, Capital_Name, Capital_Population, Country_Nr and Country_Name as attributes.
I know the table is chaotic so I brought it to 3NF :
Capital table : Capital_Nr, Capital_Name, Capital_Population, Country_Nr(foreign key)
Country table : Country_Nr and Country_Name
Ok so I guess the table should be now in 3NF, but what intrigues me is in what NF the table originally was. I tried then to use Codd's definition of 2NF : "a 1NF table is in 2NF if and only if none of its non-prime attributes are functionally dependent on a part (proper subset) of a candidate key". In my opinion the original candidate keys could only be {Capital_Nr},{Country_Nr} and {Country_Name}, each one of them single, i.e. separate from each other. So, as there is no composite candidate key, I can affirm that the original table was in 2NF. Am I right ?
Thanks !
I am wondering what normal disk I/O should be.
i know it verys depending on use but im looking for an average.
here is an idea of what we have
there is about 10 centers doing replication to our primary server.
we have about 80 users connecting directoy to our primary server using MS Dynamics through CITRIX.
we have a few other apps use the database as well however i am fairly certin its Dynamics generating our disk IO
Hardware wise we have a powerful blade connected to a raid 5 SAN with 15000 rpm disks.
normaly the disk IO stays fairly low but every so often it goes crazy and im thinking it shouldn't
Below is a sample of our disk IO from perfmon over 2 minutes or so. as you can see everything looks ok untill 04/15/2008 10:12:49.470 when the Disk I/O % goes above 100%
"04/15/2008 10:12:23.470","2.8300181121159178"
"04/15/2008 10:12:24.470","0"
"04/15/2008 10:12:25.470","3.950025280161793"
"04/15/2008 10:12:26.470","0"
"04/15/2008 10:12:27.470","0"
"04/15/2008 10:12:28.470","5.9800382722449426"
"04/15/2008 10:12:29.470","7.7400495363170325"
"04/15/2008 10:12:30.470","3.4500220801413128"
"04/15/2008 10:12:31.470","0"
"04/15/2008 10:12:32.470","4.180026752171214"
"04/15/2008 10:12:33.470","3.8600247041581071"
"04/15/2008 10:12:34.470","0"
"04/15/2008 10:12:35.470","142.71091334984544"
"04/15/2008 10:12:36.470","0"
"04/15/2008 10:12:37.470","1.1500073600471041"
"04/15/2008 10:12:38.470","0.81000518403317789"
"04/15/2008 10:12:39.470","0"
"04/15/2008 10:12:40.470","2.1400136960876548"
"04/15/2008 10:12:41.470","10.230065472419025"
"04/15/2008 10:12:42.470","4.5800293121875981"
"04/15/2008 10:12:43.470","0"
"04/15/2008 10:12:44.470","0"
"04/15/2008 10:12:45.470","14.500092800593926"
"04/15/2008 10:12:46.470","6.730043072275663"
"04/15/2008 10:12:47.470","1.6300104320667652"
"04/15/2008 10:12:48.470","7.3500470403010585"
"04/15/2008 10:12:49.470","264.66169383484055"
"04/15/2008 10:12:50.470","324.18207476527851"
"04/15/2008 10:12:51.470","536.17343150996169"
"04/15/2008 10:12:52.470","270.31172999507197"
"04/15/2008 10:12:53.470","331.97212462159757"
"04/15/2008 10:12:54.470","333.84213658967417"
"04/15/2008 10:12:55.470","435.57278766584108"
"04/15/2008 10:12:56.470","442.31283080211716"
"04/15/2008 10:12:57.470","685.92438991609549"
"04/15/2008 10:12:58.470","295.1618890360898"
"04/15/2008 10:12:59.470","61.470393410517829"
"04/15/2008 10:13:00.470","56.360360706308519"
"04/15/2008 10:13:01.470","45.260289665853861"
"04/15/2008 10:13:02.470","224.58143732119885"
"04/15/2008 10:13:03.470","1022.0365410338626"
"04/15/2008 10:13:04.470","1114.6271336136551"
"04/15/2008 10:13:05.470","241.52154573789269"
"04/15/2008 10:13:06.470","506.79324347675828"
"04/15/2008 10:13:07.470","374.88239924735518"
"04/15/2008 10:13:08.470","359.5723012627281"
"04/15/2008 10:13:09.485","427.62119831413077"
"04/15/2008 10:13:10.485","400.15256097639025"
"04/15/2008 10:13:11.485","1076.2868882360847"
"04/15/2008 10:13:12.485","325.94208602935055"
"04/15/2008 10:13:13.485","449.36287592240592"
"04/15/2008 10:13:14.485","344.28220340610181"
"04/15/2008 10:13:15.485","569.57364527132972"
"04/15/2008 10:13:16.485","775.02496015974498"
"04/15/2008 10:13:17.485","729.54466908588222"
"04/15/2008 10:13:18.485","778.70498371189581"
"04/15/2008 10:13:19.485","1080.1269128122422"
"04/15/2008 10:13:20.485","754.56482921490704"
"04/15/2008 10:13:21.485","999.11639434492372"
"04/15/2008 10:13:22.485","701.36448873272786"
"04/15/2008 10:13:23.485","276.26176807531567"
"04/15/2008 10:13:24.485","252.13161364232732"
"04/15/2008 10:13:25.485","533.27341294984296"
"04/15/2008 10:13:26.485","759.54486108711092"
"04/15/2008 10:13:27.485","817.11522953746908"
"04/15/2008 10:13:28.485","129.41082822930068"
"04/15/2008 10:13:29.485","158.94101722251023"
"04/15/2008 10:13:30.485","160.55102752657618"
"04/15/2008 10:13:31.485","655.87419759486454"
"04/15/2008 10:13:32.485","444.49284475420637"
"04/15/2008 10:13:33.485","272.47174381916045"
"04/15/2008 10:13:34.485","94.730606275880163"
"04/15/2008 10:13:35.485","355.28227380655238"
"04/15/2008 10:13:36.485","898.29574909279427"
"04/15/2008 10:13:37.485","1309.3783800216322"
"04/15/2008 10:13:38.485","88.200564483612695"
"04/15/2008 10:13:39.485","1.2300078720503811"
"04/15/2008 10:13:40.485","4.9400316162023437"
"04/15/2008 10:13:41.485","217.90139456892524"
"04/15/2008 10:13:42.485","373.26238887928884"
"04/15/2008 10:13:43.485","73.760472067021226"
"04/15/2008 10:13:44.485","1.4100090240577541"
"04/15/2008 10:13:45.485","34.960223745431975"
"04/15/2008 10:13:46.485","15.990102336654955"
"04/15/2008 10:13:47.485","63.580406914604247"
"04/15/2008 10:13:48.485","26.560169985087906"
"04/15/2008 10:13:49.485","11.150071360456707"
"04/15/2008 10:13:50.485","15.250097600624644"
"04/15/2008 10:13:51.485","17.010108864696736"
"04/15/2008 10:13:52.485","12.210078144500125"
"04/15/2008 10:13:53.485","95.650612163917842"
"04/15/2008 10:13:54.485","38.740247937586801"
"04/15/2008 10:13:55.485","5.6000358402293777"
"04/15/2008 10:13:56.485","1.6600106240679942"
"04/15/2008 10:13:57.485","19.590125376802412"
"04/15/2008 10:13:58.485","2.8100179841150981"
"04/15/2008 10:13:59.485","631.48404149786563"
"04/15/2008 10:14:00.485","579.14370651972172"
"04/15/2008 10:14:01.485","1.0600067840434177"
"04/15/2008 10:14:02.485","15.870101568650039"
"04/15/2008 10:14:03.485","112.28071859659903"
"04/15/2008 10:14:04.485","15.660100224641438"
"04/15/2008 10:14:05.485","4.9800318722039822"
"04/15/2008 10:14:06.485","25.44016281704203"
"04/15/2008 10:14:07.485","16.130103232660691"
"04/15/2008 10:14:08.485","5.9300379522428939"
"04/15/2008 10:14:09.485","4.8400309761982481"
"04/15/2008 10:14:10.485","2.6400168961081349"
"04/15/2008 10:14:11.485","19.430124352795858"
"04/15/2008 10:14:12.485","42.55027232174286"
"04/15/2008 10:14:13.485","37.550240321538055"
"04/15/2008 10:14:14.485","1.210007744049562"
"04/15/2008 10:14:15.485","15.930101952652498"
"04/15/2008 10:14:16.485","20.550131520841735"
"04/15/2008 10:14:17.485","4.0900261761675267"
"04/15/2008 10:14:18.485","8.0100512643280908"
"04/15/2008 10:14:19.485","1.6000102400655365"
"04/15/2008 10:14:20.485","2.3300149120954372"
"04/15/2008 10:14:21.485","1.6200103680663558"
"04/15/2008 10:14:22.485","10.730068672439504"
"04/15/2008 10:14:23.485","4.4600285441826832"
"04/15/2008 10:14:24.485","9.0300577923698704"
"04/15/2008 10:14:25.485","0"
"04/15/2008 10:14:26.485","15.550099520636932"
"04/15/2008 10:14:27.485","2.970019008121652"
"04/15/2008 10:14:28.485","64.580413314645213"
"04/15/2008 10:14:29.485","71.850459842942996"
"04/15/2008 10:14:30.485","53.220340610179903"
"04/15/2008 10:14:31.485","32.620208769336124"
"04/15/2008 10:14:32.485","1.0000064000409603"
"04/15/2008 10:14:33.485","4.8400309761982481"
"04/15/2008 10:14:34.485","8.2700529283387425"
"04/15/2008 10:14:35.485","11.160071424457115"
Hey All, I'm trying to decide what's the 'best' to use. I've been designing and creating database for a while and have pretty much always used a surrogate key and not a normal one. I've finally had some free time to start studying more so in my spare time and read up and come accross a lot of guides, articles and stories that tout that normal keys should be used whenever possible as they're a better identifier and that surrogate keys should only be used when there is not a readily available normal key. Now perhaps I'd be open to accepting that but absolutely every database I come across tends to only use surrogate keys. For example I'm doing an authentication system from scratch and am looking at the User table. Now of course the user name has to be unique, should that be the primary key or should I have a seperate column with a guid or an incrementing int or the like as the primary key? I can certainly see that username could be used. I can also see how it may be easier when looking through the data tables to identify who/what a table is refering to with a surrogate key. However it still seems sort of sloppy, for lack of a better word, to me. Where now I could have somebody's username (or any other piece of data used for this purpose) spread accross a lot of other tables. And while writting this I just thought of the scenario that perhaps somebody needs their username changed, with this method now the ids need to be changed on all the related rows of all the other tables whereas with a surrogate key it wouldn't matter. Anyways I'm mostly looking for opinions on which way to go (not just with the user sample, but more in general).Thanks.
View 2 Replies View RelatedHi all,
I've been running a long query which takes almost 39 seconds in Query Analyzer. After creating a Stored Procedure (with the same query) I expected to run it faster bcoz I heared that SP has a cache, and its a faster technique. But I didnt gain any performance improvments.
Can somebody clear my confusion, what I'm doing wrong.
Thanks!
We have a payroll database that needs to be backed up just before completing the payroll for that period. I need to create a batch file that a normal user can run that will tell the database to back up and then tell the user when it is done so they can continue working. Is there an easy way to do this without giving the users special permissions? I don't want to give them backup op status. Any help would be appreciated.
View 4 Replies View RelatedI will be taking over a database that has almost no pk's or relations(this is not my choice, but a vendors)
Management is looking at stored procs to improve performance, but I am wondering
if the db is in this state will there really be a gain. I am pushing for normalization
first, but if anybody has any ideas or opinions I would appreciate
hi friends the below query is actually what type of join whether inner join or normal query..?????
if not exists(select 'x'
from cobi_invoice_hdr h(nolock),
fin_quick_code_met q(nolock) ,
ci_adjustment_drdoc_vw z (nolock)
where h.tran_ou = @ctxt_ouinstance
and h.invoce_cat = @category_tmp
and d.so_no between @sonumberfrom and @sonumberto
and isnull(h.tran_amount,0) between @totalinvoiceamountfrom and @totalinvoiceamountto
and h.tran_date between convert(varchar(10),@invoicedatefrom,120)and convert(varchar(10),@fininvoicedateto,120)
and h.tran_no between @invoicenumberfrom and @invoicenumberto
and h.bill_to_cust between @billtocodefrom and @customerto
and h.fb_id = isnull(@fb,h.fb_id)
and h.tran_currency = isnull(@currency,h.tran_currency)
and h.createdby = isnull(@useridentity,h.createdby)
and EXISTS (select '*' from cobi_cust_custinfo_vw c(nolock)
where h.bill_to_cust = c.custcode
andc.ouid = @ou_tmp )
and z.status = q.parameter_text
and q.parameter_type = 'STATUS'
and q.parameter_category = 'STATUS'
and q.component_id = 'COBI'
and q.parameter_code = @status_tmp
and h.tran_no = z.documentno
and q.language_id = @ctxt_language
and z.language_id = @ctxt_language)
begin
'No matching invoices found.'
select @m_errorid = 514 -- Porselvi.J - COBIDMS412AT_000255
return
end
End
What is the 'sixth normal form' in the normalisation of tables in database management system.
View 3 Replies View RelatedHello,
Is performance of web application (ASP.NET + SQL Server 2005 Wrg edition + Win Server 2003 Web edition) running on server with one core duo/4 CPU generally comparable to the performance of the same application running on the same server with 2/4 physical CPU’s?
Thank you for your ideas!
Jan
My sql database is in suspect mode, please help me with step by step how can i change the suspect status to normal status, please dont provid eme the links of other site and help me in your own language
iam getting following error:
TITLE: Microsoft SQL Server Management Studio------------------------------
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------ADDITIONAL INFORMATION:
Database 'msdb' cannot be opened. It has been marked SUSPECT by recovery. See the SQL Server errorlog for more information. (Microsoft SQL Server, Error: 926)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=09.00.1399&EvtSrc=MSSQLServer&EvtID=926&LinkId=20476
------------------------------BUTTONS:
OK------------------------------Thanks in advance
Hi,
How do we make a normal Windows NT user as DBO in Sql server 2000?
Thanx
Hi
I Created table like this
CREATE TABLE Table(sno int ,EName varchar(20))
I inserted three records like this
INSERT INTO hazarath VALUES (1,'ragav')
INSERT INTO hazarath VALUES (2,'ragavRavo')
INSERT INTO hazarath VALUES (3,'ramu')
Now i want to alter sno column to identity column
how can i alter to identity
pls help me
Is it possible to create a cumulative log using SSIS? basiclly I have 5 logs which hold failed records. I would like to create a cumulative log and send it via email using SSIS.
thoughts?
thanks
So I got 2 classes one I wrote to interrogate databases using normal ADO:Mine:SqlConnection myConnection = new SqlConnection(m_sConnectionString);SqlCommand myCommand = new SqlCommand(sQuery, myConnection);myCommand.CommandTimeout = 120; // 60 Seconds TimeoutmyConnection.Open();SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);return result;Microsoft WaySqlDatabase dbSvc = new SqlDatabase(m_sConnectionString);DbCommand dbCommand = dbSvc.GetSqlStringCommand(sQuery);return ((SqlDataReader)dbSvc.ExecuteReader(dbCommand));What's faster?My way:SqlConnection myConnection = new SqlConnection(m_sConnectionString);SqlCommand myCommand = new SqlCommand(sQuery, myConnection);myCommand.CommandTimeout = 120; // 60 Seconds Timeout// Use a DataTable – required for default pagingSqlDataAdapter myAdapter = new SqlDataAdapter(myCommand);DataTable myTable = new DataTable();myAdapter.Fill(myTable);myConnection.Close();myConnection.Dispose();myConnection = null;return (myTable);Microsoft Way:SqlDatabase dbSvc = new SqlDatabase(m_sConnectionString);DbCommand dbCommand = dbSvc.GetSqlStringCommand(sQuery);DataTable dtData = null;DataSet dsData = dbSvc.ExecuteDataSet(dbCommand);dtData = dsData.Tables[0];return (dtData);Comments? Ideas?Al
View 4 Replies View RelatedHi,
I was wondering if it is possible to reference a value in a previous row as a field in a normal select statement, for example:
SELECT a.user_id, a.name, b.user_id, b.name
FROM Users a
LEFT OUTER JOIN Users b
WHERE (b.user_id = a.user_id - 1)
Unfortunantly my user_id values are not in sequence so I get null entries using that code. Instead of doing something as basic as -1 is there another way to reference the previous row?
Can we make SQL 2012 Always ON over the normal SQL Cluster 2012.
View 3 Replies View RelatedI have an application that stores xml data in an unusal manor. Basically a SQL Key column and an XML string.The XML string is not really standard XML, but it is what it is, and I'm stuck with it. It is in the format;
<row key="Value.01" xml:space="preserve"><c1>FirstName</c1><c2>LastName</c2><c3>10 Street Address, City ST 012345-1234</c3><c4>5</c4><c5>50</c5><c6>500</c6></row>
I am able to pull values out via
SELECT
p.value('(./c1)[1]', 'VARCHAR(8000)') AS c1,
p.value('(./c2)[1]', 'VARCHAR(8000)') AS c2
FROM dbo.UserXMLTable
CROSS APPLY XMLRECORD.nodes('/row') t(p)
where p.value('(./c1)[1]', 'VARCHAR(8000)') like 'First%'
However I've been struggling with selecting row with a LIKE clause. Something like ;
SELECT *
FROM dbo.F_UserXMLTable
where XMLRECORD.value('(./c1)[1]', 'VARCHAR(8000)') like 'First%'
I have tried a number of permutations of XML syntax but so far have been stumpled.
Please note "<row key="Value.01" xml:space="preserve">" has a <SP> in the name 'row key' .
I just ran across an interesting problem, that makes no sense. I
built
an SSIS package that updates a column, using an transformation
script.
Testing in Debug mode everything runs perfectly, but when I have SQL
sever agent run the package it insert null into the new column.
Any thoughts or suggestions would be greatly appreciated.
r/ Anthony
As pointed out in the SQL Express blog recently http://blogs.msdn.com/sqlexpress/archive/2006/11/15/sql-express-sp2-and-windows-vista-uac.aspx (look for the section that starts "Watch out!"), the SQL Express SP2 argument ADDUSERASADMIN will not work correctly if the user is a normal user. If the user is a member of the BUILTINAdministrators group then Vista will prompt to elevate them to allow the Admin rights to be effective.
However, my reading of the blog post is that if they are normal users, Vista will prompt for the Administrator credentials. This effectively runs the install as the Administrator user. So the ADDUSERASADMIN argument works, but adds the Administrator rather than the normal user.
This is not what I need to happen. Is there any way around this? I have a ClickOnce application. Is there any way to restrict the ClickOnce install to require the user to be a member of the BUILTINAdministrator group?
Thanks.
I'm trying to get the final result using an aggregate function.
Table looks like below;
ID ACRE Probability
1 3 0.3
2 1 0.6
3 6 0.2
4 5 0.5
5 2 0.1
First, I want to descend by probability then select all records that cumulative acre <= 8
So, final result will be:
ID ACRE Probability
2 1 0.6
4 5 0.5
Any idea how to write a script?
Thanks in advance,
Mike Jun
hyunhyo@hotmail.com
GIS reserch Group
University of Colorado
303-492-8781
I have to group the no. of employees based on month. i.e
Jan 10 employees
Feb 20 employees
Mar 30 employess
The result is to be
Jan 10
Feb 20
Mar 60.
Kindly provide the sql for getting the above result.
Thanks,
Lakshmi
SQL Server 2000 SP3Hi,How can I get the cumulative weeks from a givedate to the currentdate. I know I can get the weeknumber by using datepart(wk,getdate())but this will giveme the week number for this year. What if I want to know the number ofweeksthat have passed since june 1 2001. If I use datepart(wk,'20010106') Iwillget the week number for 2001 but I would like the number of weeksexpired between then now.Thanks,Reg
View 1 Replies View RelatedI have a table consisting of 3 columns: Parent varchar(50), Child varchar(50), Pop int.
The table is setup as follows:
Parent Child Pop
----------------------------------
Europe France 0
France Paris 1
New York New York City 10
North America United States 0
North America Canada 0
United States New York 0
United States Washington 0
Washington Redmond 200
Washington Seattle 100
World Europe 0
World North America 0
This is just some sample data modified a tiny bit from an example of a hierachical print out sample that is a stored procedure that allows me to pass any place and see all of that place's children/grandchildren.
I need to figure out how to write a query to show me cumulative sums (ROLLUP?) of the whole tree. So the output should basically be something like this (it can include parent and child columns too):
World Null 311
World Europe 1
Europe France 1
France Paris 1
World North America 310
North America United States 310
North America Canada 0
United States New York 10
United States Washington 300
New York New York City 10
Washington Redmond 200
Washington Seattle 100
Hopefully you understand what i'm looking for. I've tried using WITH ROLLUP and I also tried using an Inner Join but I'm not really sure what I need to do to pull this off. I seem to only be able to get it to work 1-2 levels deep but not through the whole tree.
Any help/ideas would be appreciated! Thank you.
In the emp table :
>
> EMPNO ENAME SAL
> ==================
> 7369 SMITH 1000
> 7499 ALLEN 2000
> 7521 WARD 3000
> 7566 JONES 4000
> 7654 MARTIN 5000
>
> there is a requirement to have a calculated col.
> called cummulative sal
>
> EMPNO ENAME SAL CUMMULATIVE_SAL
> 7369 SMITH 1000 1000
> 7499 ALLEN 2000 3000
> 7521 WARD 3000 6000
> 7566 JONES 4000 10000
> 7654 MARTIN 5000 15000
>
>
How to show this calculated col. by using one select statement?
I could get the result using Empno. in my query as --
select ename,sal,(select sum(sal) from emp k where k.empno <= e.empno) as cum from emp e order by ename
but I was asked to get the same result if empno. col is not there?
SUCKS........... the below code is giving the result but I don't know how you could use operator (<) on two strings to compare......????
select ename,sal,(select sum(sal) from emp k where k.ename <= e.ename) as cum from emp e order by ename
Someone tell me if this is the right approach or is there a better way of getting the thing done.
Hi,
I want to know how to assign a normal user to take backup,Restore and attach and detach the database in sqlserver2000.
Please can anyone help me to find out which server role or database role will suites my requirements.
Regards
Md S.Hassan
did VARCHAR(20)
SELECT top 10 CAST(did AS INT) FROM table
Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the varchar value 'cht6p575l7ry61k1npt' to data type int.
SELECT CONVERT(INT, did) FROM table
Msg 245, Level 16, State 1, Line 5
Conversion failed when converting the varchar value 'cht6p575l7ry61k1npt' to data type int.I found a SQL Function that removes all the alphabetic characters from the string and just leaves the integers.
I have a stored proc I want to convert it to either a Normal Query using A while loop or a set based operation/recursive cte as I want to run it for multiple CompanyNames. I get the error message as An INSERT EXEC statement cannot be nested when I execute if for Multiple Companies using another Cursor
If I convert it to a Function I get the below error message
Invalid use of a side-effecting operator 'EXECUTE STRING' within a function
converting this query to a normal query or let me know if there is any change which need to done to work with multiple companynames.
CREATE PROC [dbo].[USPT] @CompanyName varchar(50),@tablename varchar(50)
AS
BEGIN
-- EXEC [USPT] 'xyz corp','Sales Header'
DECLARE @str1 VARCHAR (MAX)
set @str1 = '
DECLARE @No VARCHAR (MAX)
[code]....
I've come accross this code and need to alter it to display a normal General Date format.
CASE WHEN p.BIRTHDTTM IS NULL THEN ''
ELSE RIGHT('0' + LTRIM(CONVERT(VARCHAR(20), BIRTHDTTM, 113)) , 20)
END AS BIRTHDTTM
The original data (which is a DOB field) looks like this
1936-08-14 00:00:00.000
And the code above is turning it into this which is good but means I cannot then format in SSRS
14 Aug 1936 00:00:00
So ideally I'd like the code above to be altered so that it gives me
14/08/1936