Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Thursday, March 29, 2012

holiday's

hi

i want to write some sort of query which will return all saturday and sunday of year 2007 with date...

thanx a lot

here you go..

Code Snippet

Declare @.Year as Int;

Declare @.Weekends Table(Date DateTime);

Declare @.Date as DateTime;

Declare @.EndDate as DateTime;

Select @.Year = 2000;

Select @.Date = Cast(Cast(@.Year as Varchar) + '-01-01' as Datetime) ,

@.EndDate = Cast(Cast(@.Year as Varchar) + '-12-31' as Datetime);

Select @.Date = DateAdd(DD,7-Datepart(w,@.Date),@.Date);

While @.Date <= @.EndDate

Begin

Insert Into @.Weekends

Select @.Date

Union All

Select DateAdd(DD,1,@.Date);

Select @.Date = DateAdd(DD,7,@.Date);

End

Select * From @.Weekends

|||

Hi,

I hope the below query may help you

declare @.date as datetime

select @.date = dateadd(dd, -1 * datepart(dy, getdate()) + 1, getdate())

while year(@.date)=2007

begin

if DATEPART(dw, @.date) in (1,7)

print cast(@.date as varchar(10))

set @.date = dateadd(dd,1,@.date)

end

Eralper

http://www.kodyaz.com

|||

hey mani thanx for reply...

i want date with day...i mean the corresponding date is saturday or sunday .......how we can do?

|||

Here it is with day..

Code Snippet

Declare @.Year as Int;

Declare @.Weekends Table(Date DateTime,Day varchar(10));

Declare @.Date as DateTime;

Declare @.EndDate as DateTime;

Select @.Year = 2006;

Select @.Date = Cast(Cast(@.Year as Varchar) + '-01-01' as Datetime) ,

@.EndDate = Cast(Cast(@.Year as Varchar) + '-12-31' as Datetime);

Select @.Date = DateAdd(DD,1-Datepart(w,@.Date),@.Date);

While @.Date <= @.EndDate

Begin

Insert Into @.Weekends

Select DateAdd(DD,-1,@.Date), Datename(dw,DateAdd(DD,-1,@.Date)) Where Year(DateAdd(DD,-1,@.Date)) = @.Year

Union

Select @.Date, Datename(dw,@.Date) Where Year(@.Date) = @.Year

Select @.Date = DateAdd(DD,7,@.Date);

End

Select * From @.Weekends

|||

yes mani this is my need thanx a lot....but here i m getting one entry of 2006-12-31 00:00:00.000......

Select @.Year = 2007;

here i set @.year 2007 but i m getting one entry of 2006...i don't want that entry....

sorry for trouble...


|||opps yes.. Fixed it..|||thanx a lot|||welcome.. |||

declare @.date as datetime
declare @.year as int
set @.year=2007
Declare @.Weekends Table(Date varchar(12),[Day] varchar(10));
select @.date = dateadd(dd, -1 * datepart(dy, getdate()) + 1, getdate())
while year(@.date)=@.year
begin
if DATEPART(dw, @.date) in (1,7)
begin
Insert Into @.Weekends
select cast(@.date as varchar(12)),cast(DATENAME(dw,@.Date) as varchar(10))
end
set @.date = dateadd(dd,1,@.date)
end
Select * From @.Weekends

holiday's

hi

i want to write some sort of query which will return all saturday and sunday of year 2007 with date...

thanx a lot

here you go..

Code Snippet

Declare @.Year as Int;

Declare @.Weekends Table(Date DateTime);

Declare @.Date as DateTime;

Declare @.EndDate as DateTime;

Select @.Year = 2000;

Select @.Date = Cast(Cast(@.Year as Varchar) + '-01-01' as Datetime) ,

@.EndDate = Cast(Cast(@.Year as Varchar) + '-12-31' as Datetime);

Select @.Date = DateAdd(DD,7-Datepart(w,@.Date),@.Date);

While @.Date <= @.EndDate

Begin

Insert Into @.Weekends

Select @.Date

Union All

Select DateAdd(DD,1,@.Date);

Select @.Date = DateAdd(DD,7,@.Date);

End

Select * From @.Weekends

|||

Hi,

I hope the below query may help you

declare @.date as datetime

select @.date = dateadd(dd, -1 * datepart(dy, getdate()) + 1, getdate())

while year(@.date)=2007

begin

if DATEPART(dw, @.date) in (1,7)

print cast(@.date as varchar(10))

set @.date = dateadd(dd,1,@.date)

end

Eralper

http://www.kodyaz.com

|||

hey mani thanx for reply...

i want date with day...i mean the corresponding date is saturday or sunday .......how we can do?

|||

Here it is with day..

Code Snippet

Declare @.Year as Int;

Declare @.Weekends Table(Date DateTime,Day varchar(10));

Declare @.Date as DateTime;

Declare @.EndDate as DateTime;

Select @.Year = 2006;

Select @.Date = Cast(Cast(@.Year as Varchar) + '-01-01' as Datetime) ,

@.EndDate = Cast(Cast(@.Year as Varchar) + '-12-31' as Datetime);

Select @.Date = DateAdd(DD,1-Datepart(w,@.Date),@.Date);

While @.Date <= @.EndDate

Begin

Insert Into @.Weekends

Select DateAdd(DD,-1,@.Date), Datename(dw,DateAdd(DD,-1,@.Date)) Where Year(DateAdd(DD,-1,@.Date)) = @.Year

Union

Select @.Date, Datename(dw,@.Date) Where Year(@.Date) = @.Year

Select @.Date = DateAdd(DD,7,@.Date);

End

Select * From @.Weekends

|||

yes mani this is my need thanx a lot....but here i m getting one entry of 2006-12-31 00:00:00.000......

Select @.Year = 2007;

here i set @.year 2007 but i m getting one entry of 2006...i don't want that entry....

sorry for trouble...


|||opps yes.. Fixed it..|||thanx a lot|||welcome.. |||

declare @.date as datetime
declare @.year as int
set @.year=2007
Declare @.Weekends Table(Date varchar(12),[Day] varchar(10));
select @.date = dateadd(dd, -1 * datepart(dy, getdate()) + 1, getdate())
while year(@.date)=@.year
begin
if DATEPART(dw, @.date) in (1,7)
begin
Insert Into @.Weekends
select cast(@.date as varchar(12)),cast(DATENAME(dw,@.Date) as varchar(10))
end
set @.date = dateadd(dd,1,@.date)
end
Select * From @.Weekends

sql

Tuesday, March 27, 2012

Hitting an Oracle view

I have been asked to include a view from our Oracle system in one of my SQL queries. As a programmer I can write querries all day long, but I have no administration skills.

Can someone just give me the basics on creating this ability? On my development system I have installed the Oracle client and configured an ODBC driver that points to the Oracle views. This has allowed me to create a linked table in Access, but I have never attempted to port this to SQL Server 2k.

I assume I just load the drivers on the production system as before, but do I then use an ODBC driver again, or is there a better method with SQL Server? If its the ODBC method, then how do I add a linked table in SQL?

Sorry for the basic questions, and I really appreciate any help.

Thansks,

RobI'd suggest just using the Microsoft provided drivers unless you need specific Oracle functionality. It makes life a lot simpler in the long run.

Just use Enterprise Mangler or sp_addlinkedserver to make the Oracle server a linked server from your SQL Server, and life ought to be lovely. I don't remember needing to add any drivers to make it work, but I almost always use the Enterprise Edition of MS-SQL so I'm not always aware of what ships/installs with other editions.

-PatP|||Thanks for that tip - I have looked into sp_addlinkedserver and I can probably figure it out, but using the mangler just seems easier to me. If I start up the register server wizard, it seems to only be looking for SQL servers. I don't see any way to change the provider. Is it possible that the developer edition I am using doesn't have the functionality?|||Like so:

-PatPsql

Monday, March 26, 2012

hii

Write SQL Queries for the following:

Cust

Cust_ID

Name

1

AA

2

BB

3

CC

4

DD

5

EE

Ord

Ord_ID

Cust_ID

Amt

Tran_Type

From_Ord_ID

1

1

10

D

NULL

2

1

20

D

NULL

3

2

30

D

NULL

4

2

40

D

NULL

5

2

NULL

D

NULL

6

3

NULL

D

NULL

7

4

40

D

NULL

8

4

50

D

NULL

9

4

-10

C

7

10

4

-20

C

8

11

4

-30

C

8


<!--[endif]-->Write a query that shows the balance for customer DD by trans_type. Consider a Tran_type of “C” to be a transactional adjustment to the associated original “D” record. The result should be as follows.

Name

D

C

Balance

DD

40

-10

30

(It looks like that time of year again, when we start getting requests to do class assignments.)

Subhash,

Please post the efforts you have made up to now, and we can help guide you to a correct solution. I just don't think that you will find folks here willing to do your classwork for you. Also post the table DDL, and sample data in the form of INSERT statements. If you need help with that concept, check here or here.

|||

hahaha.

well its actually easy. you need to use join

and sum function and group by

sql

Wednesday, March 21, 2012

High pages/sec.. memory pressure ?

When I see high pages/sec, does SQL go to the pagefile to read or write
pages that need to be flushed out of physical memory or to be retrieved into
physical memory?Yes, that is what the pages/sec counter is measuring.
What numbers are you seeing? If you average 20 pages/sec or less you
are within the design of a standard installation of sql server. If I
was seeing more than 20, I would be adding more memory after some
obvious checking (size of pagefile and its utilization: page file: %
usage) That will give you a good idea of how much benefit extra
memory will give you too
On Jan 1, 9:41=A0pm, "Hassan" <has...@.test.com> wrote:
> When I see high pages/sec, does SQL go to the pagefile to read or write
> pages that need to be flushed out of physical memory or to be retrieved in=to
> physical memory?|||It depends on how you have your memory configured. A better counter to
monitor for memory pressure is page life expectancy.
--
Jason Massie
Web: http://statisticsio.com
RSS: http://feeds.feedburner.com/statisticsio
"Hassan" <hassan@.test.com> wrote in message
news:%23NNZlIQTIHA.280@.TK2MSFTNGP03.phx.gbl...
> When I see high pages/sec, does SQL go to the pagefile to read or write
> pages that need to be flushed out of physical memory or to be retrieved
> into physical memory?|||I'd also veryfy whether pages/sec was caused by the SQL Server process or by
some other apps.
Linchi
"Hassan" wrote:
> When I see high pages/sec, does SQL go to the pagefile to read or write
> pages that need to be flushed out of physical memory or to be retrieved into
> physical memory?
>|||How do you verify that Linchi ?
"Linchi Shea" <LinchiShea@.discussions.microsoft.com> wrote in message
news:5C03FF55-90CE-4B88-9D9E-6AC3B562EB34@.microsoft.com...
> I'd also veryfy whether pages/sec was caused by the SQL Server process or
> by
> some other apps.
> Linchi
> "Hassan" wrote:
>> When I see high pages/sec, does SQL go to the pagefile to read or write
>> pages that need to be flushed out of physical memory or to be retrieved
>> into
>> physical memory?
>>|||You can check page faults/sec for the SQL Server process either under the
perfmon instance Process\<sql process> or using Task Manager by adding the
page faults column on the Processes tab. Now, page faults are not a hard
paging indicator for the process as Pages/sec is for the OS. That is, you
can't necessarily say that a process is causing hard paging if it has high
page faults. But page faults may give you an indication. So if you see no
other process but the SQL process incurring page faults that nicely correlate
with the occurence of hard paging, you have reason to suspect the hard paging
si caused by the SQL process.
Linchi
"Hassan" wrote:
> How do you verify that Linchi ?
> "Linchi Shea" <LinchiShea@.discussions.microsoft.com> wrote in message
> news:5C03FF55-90CE-4B88-9D9E-6AC3B562EB34@.microsoft.com...
> > I'd also veryfy whether pages/sec was caused by the SQL Server process or
> > by
> > some other apps.
> >
> > Linchi
> >
> > "Hassan" wrote:
> >
> >> When I see high pages/sec, does SQL go to the pagefile to read or write
> >> pages that need to be flushed out of physical memory or to be retrieved
> >> into
> >> physical memory?
> >>
> >>
>

High Latch Waits.. what would they indicate ?

If there is high contention to write to a single page especially since it
has an identity column and everything wants to be written to the same page
in one go, would that lead to latch waits and if so, how can we circumvent ?
Right now, we have a flurry of application servers that want to write to
this one particular table and at times its very heavy contention..
Does SQL server lets multiple apps to write to the same page for the same
table at the same time ? I thought locks would prevent it from happening..no
?If that's the problem, the obvious question is, can you avoid or reduce
writing to the same page?
Linchi
"Hassan" wrote:
> If there is high contention to write to a single page especially since it
> has an identity column and everything wants to be written to the same page
> in one go, would that lead to latch waits and if so, how can we circumvent ?
> Right now, we have a flurry of application servers that want to write to
> this one particular table and at times its very heavy contention..
> Does SQL server lets multiple apps to write to the same page for the same
> table at the same time ? I thought locks would prevent it from happening..no
> ?
>
>

Friday, March 9, 2012

High "Disk Write Bytes/sec" in Mirror server

I have do some benchmark test between the "Principle", "Mirror" and "Witness", things seems normal, the System usage (CPU, Disk Read/Write) on the "Witness" is very small and the CPU usage on Principle and Mirror is similar, However....

For the "Disk Write Bytes/sec", the usage on Principle is 200,000 and the Mirror is 1,500,000, the mirror server is talking about x7 times Disk Write Bytes/sec on the Mirror.

I cannot think of any reason why the Disk Write Bytes /sec is so much higher than the Principle, can somebody help me?

Hi Benny,

Just curious - is the mirrored database the only thing that's running on the mirror machine, or you may have other workloads there?

Could you please run the sp_dbmmonitorresults stored proc on the principal and the mirror, and check whether the send and receive queues show something reasonable?

-- Kaloian.

|||

Hi Kaloian, in the mirror server, I find 19 row but only 1 row in the principle server, is it normal?

According to the result of sp_dbmmonitorresults, I find that the transaction delay on the mirror server is quite long. We are using hardware RAID-5 on the Principle server and normal disk (no RAID) on mirror server, will it increase the write byte /sec, because of the slower in "disk" speed, should be make it lower, am I right?

Thank you very much for your help.

This are the result for your reference:

On Principle Server:

all the counter are "0"

On Mirror Server:

database namerolemirroring_statewitness_statuslog_generation_rateunsent_logsend_rateunrestored_logrecovery_ratetransaction_delaytransactions_per_secaverage_delaytime_recordedTime_behindlocal_time
Mirror2142710710026744630:00.729:00.130:00.7
Mirror2141830830032450629:00.129:00.129:00.1
Mirror2141740740039742928:01.028:01.028:01.0
Mirror21410000001027:00.827:00.827:00.8
Mirror21410000001026:00.726:00.726:00.7
Mirror21410000001025:00.525:00.525:00.5
Mirror21410000001024:00.424:00.424:00.4
Mirror21410000001023:00.223:00.223:00.2
Mirror21410000001022:00.122:00.122:00.1
Mirror21410000001021:00.921:00.921:00.9
Mirror21410000001020:00.820:00.820:00.8
Mirror21417070082419:00.619:00.619:00.6
Mirror21410000021218:00.518:00.518:00.5
Mirror21410000001017:00.317:00.317:00.3
Mirror21410000001016:00.216:00.216:00.2
Mirror21410000000015:40.215:40.215:40.2
Mirror21210000000044:00.115:40.244:00.1
Mirror21210000000043:00.115:40.243:00.1
Mirror21210000000042:00.115:40.242:00.1

High "Disk Write Bytes/sec" in Mirror server

I have do some benchmark test between the "Principle", "Mirror" and "Witness", things seems normal, the System usage (CPU, Disk Read/Write) on the "Witness" is very small and the CPU usage on Principle and Mirror is similar, However....

For the "Disk Write Bytes/sec", the usage on Principle is 200,000 and the Mirror is 1,500,000, the mirror server is talking about x7 times Disk Write Bytes/sec on the Mirror.

I cannot think of any reason why the Disk Write Bytes /sec is so much higher than the Principle, can somebody help me?

Hi Benny,

Just curious - is the mirrored database the only thing that's running on the mirror machine, or you may have other workloads there?

Could you please run the sp_dbmmonitorresults stored proc on the principal and the mirror, and check whether the send and receive queues show something reasonable?

-- Kaloian.

|||

Hi Kaloian, in the mirror server, I find 19 row but only 1 row in the principle server, is it normal?

According to the result of sp_dbmmonitorresults, I find that the transaction delay on the mirror server is quite long. We are using hardware RAID-5 on the Principle server and normal disk (no RAID) on mirror server, will it increase the write byte /sec, because of the slower in "disk" speed, should be make it lower, am I right?

Thank you very much for your help.

This are the result for your reference:

On Principle Server:

all the counter are "0"

On Mirror Server:

database namerolemirroring_statewitness_statuslog_generation_rateunsent_logsend_rateunrestored_logrecovery_ratetransaction_delaytransactions_per_secaverage_delaytime_recordedTime_behindlocal_time
Mirror2142710710026744630:00.729:00.130:00.7
Mirror2141830830032450629:00.129:00.129:00.1
Mirror2141740740039742928:01.028:01.028:01.0
Mirror21410000001027:00.827:00.827:00.8
Mirror21410000001026:00.726:00.726:00.7
Mirror21410000001025:00.525:00.525:00.5
Mirror21410000001024:00.424:00.424:00.4
Mirror21410000001023:00.223:00.223:00.2
Mirror21410000001022:00.122:00.122:00.1
Mirror21410000001021:00.921:00.921:00.9
Mirror21410000001020:00.820:00.820:00.8
Mirror21417070082419:00.619:00.619:00.6
Mirror21410000021218:00.518:00.518:00.5
Mirror21410000001017:00.317:00.317:00.3
Mirror21410000001016:00.216:00.216:00.2
Mirror21410000000015:40.215:40.215:40.2
Mirror21210000000044:00.115:40.244:00.1
Mirror21210000000043:00.115:40.243:00.1
Mirror21210000000042:00.115:40.242:00.1