Showing posts with label queries. Show all posts
Showing posts with label queries. Show all posts

Wednesday, March 28, 2012

Please help in queries

Hi,

I have 5 tables in sql database, naming Book, Category, Subject, UserDownload, User.

In Book table, BookID, BookTitle, CategoryID

In Category table, CategoryID, CategoryName

In Subject table, SubjectID, SubjectName, CategoryID

In UserDownload table, UserID, BookID

In User table, UserID, UserName

I used Book to store information of books. Those books has many categories. In those categories, there is also some subjects.

When user downloads book, I update UserDownload table.

The result I want to get is, Top Ten Download Subject. How can I get? Please help me.

The way I approach this kind of query is to first list the columns I need to return. Then I start thinking about which tables I need to touch to get that data, and then I think about how the data is related. Something like this should work for you:

SELECT
Subject.SubjectID,
Subject.SubjectName,
TopDownloads.BookCount
FROM
Subject
INNER JOIN
Book ON Subject.CategoryID = Book.CategoryID
INNER JOIN
(SELECT TOP 10 BookID, COUNT(*) AS BookCount FROM UserDownload GROUP BY BookID ORDER BY COUNT(*) DESC) AS TopDownloads ON Book.BookID = TopDownloads.BookID

Friday, March 23, 2012

Please give kind attension to my queries very urgent

Please give kind attension to my queries

When I am giving like http://localhost/ReportServer the following message is coming in explorer. What I have to do please help

Reporting Services Error

The version of the report server database is either in a format that is not valid, or it cannot be read. The found version is 'Unknown'. The expected version is 'C.0.8.40'. To continue, update the version of the report server database and verify access rights. (rsInvalidReportServerDatabase) Get Online Help

SQL Server Reporting Services

Moving to RS forum.

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

|||What version of reporting services are you using and what version of sql server did you point it to?|||

Thanku for attension

I am using version SQL server 2005

|||

This thread may help.

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

cheers,

Andrew

sql

please fine tune these queries

programmers are writing a loop in .net and passing empid,date to server
there are 700 employees so the round trips are increasing
--queries
select '8/5/2005' as daysabsent,e.empid as empid,intime,type,cast('8/5/2005'
as datetime) as absentdays,'A'
from ccsmay26.dbo.employee as e
left outer join
(
select empid,intime,type=case when intime>='12/30/1899 9:00:00 PM' then 'N'
else 'M' end
from
(
select empid,effective_date,end_date,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
/***********************/
and empid='QU'
/***********************/
union
select empid,effective_date,null as end_date,intime
from newccs.dbo.intimings
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
) as a
) as t
on e.empid=t.empid
where depid<>'UST' and
(
(emp_status<>'T' and hire_date<='8/1/2005') or (emp_status='T' and
termination_date>'8/5/2005')
)
and e.empid='QU' and e.empid not in
(
/*****************Calculation of no. of days absent of an
employee***********************/
select empid
from
(
SELECT DISTINCT CAST(DATE1 AS DATETIME) as daysabsent,empid
FROM
(
/*****************Employees of the Night shift********************/
SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
AS VARCHAR(2)) +'/'+
CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
left outer join
(
select empid,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
/***********************/
and empid='QU'
/***********************/
union
select empid,intime
from newccs.dbo.intimings
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
) as i
on e.empid=i.empid
where entrytime>='8/5/2005 8:00:00 PM' and
entrytime<=dateadd(d,1,'8/5/2005 5:00:00 PM') and intime>='12/30/1899
9:00:00 PM'
--Changes by me, e.empid has to be removed
/*and e.empid='CL'*/ and e.timetype in ('S') --and e.inout='S'
union
/******************Employees of the Morning shift******************/
SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
AS VARCHAR(2))
+'/'+CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
left outer join
(
select empid,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
/***********************/
and empid='QU'
/***********************/
union
select empid,intime
from newccs.dbo.intimings
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
) as i
on e.empid=i.empid
where entrytime>='8/5/2005' and entrytime<=dateadd(d,1,'8/5/2005') and
intime<'12/30/1899 9:00:00 PM'
--Changes by me, e.empid has to be removed
/*and e.empid='CL'*/ and e.timetype in ('S') --and e.inout='S'
) as z
) as z /*** Absent employees of Day & Night Shift represented as 'z' ***/
)
/*********** End of calculation of Absent days ************/
union
/*************************** Start of calculation of Present days
**************************************/
select '8/5/2005' as daysabsent,e.empid as empid,intime,type,cast('8/5/2005'
as datetime) as absentdays,'P'
from ccsmay26.dbo.employee as e
left outer join
(
select empid,intime,type=case when intime>='12/30/1899 9:00:00 PM' then 'N'
else 'M' end
from
(
select empid,effective_date,end_date,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
/***********************/
and empid='QU'
/***********************/
union
select empid,effective_date,null as end_date,intime
from newccs.dbo.intimings
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
) as a
) as t
on e.empid=t.empid
where depid<>'UST' and
(
(emp_status<>'T' and hire_date<='8/1/2005') or (emp_status='T' and
termination_date>'8/5/2005')
)
and e.empid='QU' and e.empid in
(
/*****************Calculation of no. of days absent of an
employee***********************/
select empid
from
(
SELECT DISTINCT CAST(DATE1 AS DATETIME) as daysabsent,empid
FROM
(
/*****************Employees of the Night shift********************/
SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
AS VARCHAR(2)) +'/'+
CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
left outer join
(
select empid,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
/***********************/
and empid='QU'
/***********************/
union
select empid,intime
from newccs.dbo.intimings
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
) as i
on e.empid=i.empid
where entrytime>='8/5/2005 8:00:00 PM' and
entrytime<=dateadd(d,1,'8/5/2005 5:00:00 PM') and intime>='12/30/1899
9:00:00 PM'
--Changes by me, e.empid has to be removed
/*and e.empid='CL'*/ and e.timetype='S' and e.inout='S' --and e.timetype
not in ('V','B')
union
/******************Employees of the Morning shift******************/
SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
AS VARCHAR(2))
+'/'+CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
left outer join
(
select empid,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
/***********************/
and empid='QU'
/***********************/
union
select empid,intime
from newccs.dbo.intimings
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
) as i
on e.empid=i.empid
where entrytime>='8/5/2005' and entrytime<=dateadd(d,1,'8/5/2005') and
intime<'12/30/1899 9:00:00 PM'
--Changes by me, e.empid has to be removed
/*and e.empid='CL'*/ and e.timetype='S' and e.inout='S' --and e.timetype
not in ('V','B')
) as z
) as z /*** Absent employees of Day & Night Shift represented as 'z' ***/
)
--end queri3esRags
Can you post DDL/sample data and description on desired out put
--
Regards
R.D
--Knowledge gets doubled when shared
"raghu veer" wrote:

> programmers are writing a loop in .net and passing empid,date to server
> there are 700 employees so the round trips are increasing
> --queries
> select '8/5/2005' as daysabsent,e.empid as empid,intime,type,cast('8/5/200
5'
> as datetime) as absentdays,'A'
> from ccsmay26.dbo.employee as e
> left outer join
> (
> select empid,intime,type=case when intime>='12/30/1899 9:00:00 PM' then '
N'
> else 'M' end
> from
> (
> select empid,effective_date,end_date,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,effective_date,null as end_date,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
> ) as a
> ) as t
> on e.empid=t.empid
> where depid<>'UST' and
> (
> (emp_status<>'T' and hire_date<='8/1/2005') or (emp_status='T' and
> termination_date>'8/5/2005')
> )
> and e.empid='QU' and e.empid not in
> (
> /*****************Calculation of no. of days absent of an
> employee***********************/
> select empid
> from
> (
> SELECT DISTINCT CAST(DATE1 AS DATETIME) as daysabsent,empid
> FROM
> (
> /*****************Employees of the Night shift********************/
> SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
> AS VARCHAR(2)) +'/'+
> CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
> FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
> left outer join
> (
> select empid,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
> ) as i
> on e.empid=i.empid
> where entrytime>='8/5/2005 8:00:00 PM' and
> entrytime<=dateadd(d,1,'8/5/2005 5:00:00 PM') and intime>='12/30/1899
> 9:00:00 PM'
> --Changes by me, e.empid has to be removed
> /*and e.empid='CL'*/ and e.timetype in ('S') --and e.inout='S'
> union
> /******************Employees of the Morning shift******************/
> SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
> AS VARCHAR(2))
> +'/'+CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
> FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
> left outer join
> (
> select empid,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
> ) as i
> on e.empid=i.empid
> where entrytime>='8/5/2005' and entrytime<=dateadd(d,1,'8/5/2005') and
> intime<'12/30/1899 9:00:00 PM'
> --Changes by me, e.empid has to be removed
> /*and e.empid='CL'*/ and e.timetype in ('S') --and e.inout='S'
> ) as z
> ) as z /*** Absent employees of Day & Night Shift represented as 'z' ***/
> )
> /*********** End of calculation of Absent days ************/
> union
> /*************************** Start of calculation of Present days
> **************************************/
> select '8/5/2005' as daysabsent,e.empid as empid,intime,type,cast('8/5/200
5'
> as datetime) as absentdays,'P'
> from ccsmay26.dbo.employee as e
> left outer join
> (
> select empid,intime,type=case when intime>='12/30/1899 9:00:00 PM' then '
N'
> else 'M' end
> from
> (
> select empid,effective_date,end_date,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,effective_date,null as end_date,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
> ) as a
> ) as t
> on e.empid=t.empid
> where depid<>'UST' and
> (
> (emp_status<>'T' and hire_date<='8/1/2005') or (emp_status='T' and
> termination_date>'8/5/2005')
> )
> and e.empid='QU' and e.empid in
> (
> /*****************Calculation of no. of days absent of an
> employee***********************/
> select empid
> from
> (
> SELECT DISTINCT CAST(DATE1 AS DATETIME) as daysabsent,empid
> FROM
> (
> /*****************Employees of the Night shift********************/
> SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
> AS VARCHAR(2)) +'/'+
> CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
> FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
> left outer join
> (
> select empid,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
> ) as i
> on e.empid=i.empid
> where entrytime>='8/5/2005 8:00:00 PM' and
> entrytime<=dateadd(d,1,'8/5/2005 5:00:00 PM') and intime>='12/30/1899
> 9:00:00 PM'
> --Changes by me, e.empid has to be removed
> /*and e.empid='CL'*/ and e.timetype='S' and e.inout='S' --and e.timetyp
e
> not in ('V','B')
> union
> /******************Employees of the Morning shift******************/
> SELECT e.*,CAST(MONTH(ENTRYTIME) AS VARCHAR(2))+'/'+CAST(DAY(ENTRYTIME)
> AS VARCHAR(2))
> +'/'+CAST(YEAR(ENTRYTIME) AS VARCHAR(4)) AS DATE1
> FROM NEWCCS.DBO.EMPLOYEE_TIMINGS as e
> left outer join
> (
> select empid,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
> ) as i
> on e.empid=i.empid
> where entrytime>='8/5/2005' and entrytime<=dateadd(d,1,'8/5/2005') and
> intime<'12/30/1899 9:00:00 PM'
> --Changes by me, e.empid has to be removed
> /*and e.empid='CL'*/ and e.timetype='S' and e.inout='S' --and e.timetyp
e
> not in ('V','B')
> ) as z
> ) as z /*** Absent employees of Day & Night Shift represented as 'z' ***/
> )
> --end queri3es|||On Tue, 4 Oct 2005 00:05:04 -0700, raghu veer wrote:

>programmers are writing a loop in .net and passing empid,date to server
>there are 700 employees so the round trips are increasing
(snip)
Hi Raghu,
The above suggests that your query is executed once for each employee.
If that is true, than your first goal should be to rewrite the querty
such that it will process all employees in one pass. Not only to get
back from 700 roundtrips to one, but also to enable SQL Server to create
a much more efficient execution plan.
Unfortunately, your posted SQL is way too long for an in-depth analysis
in the time that I can spare here. Some observations:
- Use unambiguous date and datetime formats:
yyyymmdd (date only),
yyyy-mm-ddThh:mm:ss (date and time), and
yyyy-mm-ddThh:mm:ss.mmm (ditto, incl milliseconds)
- Check if you can use UNION ALL instead of UNION. The latter will
attempt to remove duplicates, whereas the first won't. If you know
you'll never have duplicates, you can safely use UNION ALL and save the
server some work.
- There is some needless complexion in your code. The code below just
struck me:
> select empid,effective_date,end_date,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,effective_date,null as end_date,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
is equivalent to
select empid,effective_date,end_date,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
There might be more similar code; I didn't look for it.
- I get the feeling that you have the same subqueries repeated several
times in your code. This is sometimes necessary - but it can often be
eliminated.
If you want more help, then instead of posting a 200+ line query, post
the following information instead. Check www.,aspfaq.com/5006 as well.
* CREATE TABLE statements for all tables involved in your problem,
including all constraints and properties. Irrelevant columns may be
omitted.
* INSERT statements with a few rows of sample data. We don't need
hundred's of rows - just enough (but not less!!) to illustrate what
you're trying to do and what the important exceptions (if any!) are.
* Expected results.
* A description of the business problem, including all business rules we
need to know in order to solve the problem.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hugo,
Not trying to be picky, but you must have missed this in your quick
read:
select empid,effective_date,
end_date = CASE WHEN '8/5/2005'<=end_date
THEN end_date
ELSE NULL END,
intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
Didn't want the OP focusing on a typo when there are larger issues at
hand.
Stu
Hugo Kornelis wrote:
> On Tue, 4 Oct 2005 00:05:04 -0700, raghu veer wrote:
> - There is some needless complexion in your code. The code below just
> struck me:
> is equivalent to
> select empid,effective_date,end_date,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/|||Raghu
Better Construct from scratch.Dont try to reconstruct. It is in complete mes
s.
--
Regards
R.D
--Knowledge gets doubled when shared
"Stu" wrote:

> Hugo,
> Not trying to be picky, but you must have missed this in your quick
> read:
> select empid,effective_date,
> end_date = CASE WHEN '8/5/2005'<=end_date
> THEN end_date
> ELSE NULL END,
> intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
> Didn't want the OP focusing on a typo when there are larger issues at
> hand.
> Stu
> Hugo Kornelis wrote:
>|||On 4 Oct 2005 19:01:39 -0700, Stu wrote:

>Hugo,
>Not trying to be picky, but you must have missed this in your quick
>read:
> select empid,effective_date,
> end_date = CASE WHEN '8/5/2005'<=end_date
> THEN end_date
> ELSE NULL END,
> intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
>Didn't want the OP focusing on a typo when there are larger issues at
>hand.
Hi Stu,
I'm quite sure I missed a lot of things in my quick read :-)
However, I've been starting at this snippet for some time now, thinking
that there must be a reason that you singled this out. But I still fail
to see what is wrong with this code (apart from using non-standard date
formats and being generally hard to read because of the reversed order
for comparisons).
What am I missing?
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Hey Hugo,
Here's the OP statement:

> select empid,effective_date,end_date,intime
> from newccs.dbo.intimings_history
> where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
> /***********************/
> and empid='QU'
> /***********************/
> union
> select empid,effective_date,null as end_date,intime
> from newccs.dbo.intimings
> where '8/5/2005'>=effective_date
> /***********************/
> and empid='QU'
> /***********************/
And here's the code you posted:
select empid,effective_date,end_date,intime
from newccs.dbo.intimings_history
where '8/5/2005'>=effective_date
/***********************/
and empid='QU'
/***********************/
Note that in your statement, end_date is not NULLified in the resultset
when the '8/25/2005' > end_date. If the end_date is in the past, your
query will return a value, whereas the OP code will NULL out that
value.
Here's my simplified test:
/*CREATE TABLE TestDate (effective_date smalldatetime, end_date
smalldatetime)
INSERT INTO TestDate (effective_date, end_date)
SELECT '8/5/2005', '8/1/2005'
UNION ALL
SELECT '8/5/2005', '8/5/2005'
UNION ALL
SELECT '8/5/2005', '8/15/2005'
*/
--OP code, minus columns and a WHERE clause
select effective_date,end_date
from TestDate
where '8/5/2005'>=effective_date and '8/5/2005'<=end_date
union
select effective_date,null as end_date
from TestDate
where '8/5/2005'>=effective_date
--Hugo code, minus columns and a WHERE clause
select effective_date,end_date
from TestDate
where '8/5/2005'>=effective_date
--my code, minus columns and a WHERE clause
select effective_date,
end_date = CASE WHEN '8/5/2005'<=end_date
THEN end_date
ELSE NULL END
from TestDate
where '8/5/2005'>=effective_date
As I said in my earlier post, there are other issues that the OP needs
to resolve, and your post mentioned many of them. I just didn't want
him to struggle in trying to understand why his results would be
different in the code snippet you sampled.
Stu|||On 5 Oct 2005 14:48:54 -0700, Stu wrote:

>Hey Hugo,
(snip)
>Note that in your statement, end_date is not NULLified in the resultset
>when the '8/25/2005' > end_date. If the end_date is in the past, your
>query will return a value, whereas the OP code will NULL out that
>value.
Hi Stu,
Yoiu're absolutely right. Thanks for pointing this out.
I've now been starting for several minutes at the code, trying to figure
out how I could have madde a mistake like that. It's not just a mere
oversight - I clearly remember thinking about both aprts of the UNION,
how they interact, and that the end effect would be the same as just the
single simple query I posted. I must have had quite a brain lapse when I
wrote my reply. :-(
Dang! I just saw another thing we both overlooked thus far.
The first and the second part of the union actually don't even access
the same table.... I feel SOOOOOO stupid now!!
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||DOH!!!
"Why do you see the speck that is in your brother's eye, but don't
consider the beam that is in your own eye?"
I feel really stupid as well. And just think, this post will live on
for years.....
:)
Stu

Wednesday, March 21, 2012

Please answer my queries for fresh Installation

Hi Group,
For some reasons I have to pull the SQL Server Production
server out of network and reinstall from OS level. I have
few queries about Backing up the SQL server Databases and
choosing cluster size.
1. Do I need to Backup/detach the Master,MSDB databases
along with User database to restore again when SQL server
is installed again freshly?. MSDB just has two maintenance
plans running.I fell that I can just take the backups of
User databases as I have to restore them on fresh
installation.
2. I am creating three arrays on this server
C: RAID1 Array ( OS) - Array1
D: RAID1 (SQL Tran logs files)- Array2
D: RAID5E ( SQL Data files) - Array3
While installing SQLServer I will choose Array3 for SQL
system databases. How do i move the master.ldf msdb.ldf
model.ldf temp.ldf to Array2 ? does detach/attach work for
system databses?
3. I am choosing 8KB Cluster on NTFS instead of Default
4KB cluster, does this help in enhancing the access of 8K
SQL database pages in terms of I/O?
4. Are there any patches/fixes released after
SQLServer2000 Service Pack 3a?
OS Windows 2000 Server SP4
SQL Server 2000 Standard Edition
IBM x250 dual PIII Xeon 700MHz
4GB RAM
18GB for OS on server
1.4TB on IBM FAStT200 HA + EXP500 expansion.
Thanks for your patience
Regards
Chip
Hi,
1. This link details you the steps to move the system and user databases.
http://www.support.microsoft.com/?id=224071 Moving SQL Server
Databases to a New Location with Detach/Attach
It is always good to move the Master and MSDB databases to new server.
But it is a must that you should move master database
since it stores Server config, Logins permissions..If you are
notloading master all the database users chanin will be lost.
2. For Master database after starting sql server using trace flag "-T3608"
and use sp_detach_db and then copy to new drive and use
sp_attach_db to attach Master database. For Tempdb use ALTER DATBASE ..
MODIFY FILE option. Both methodologies are detailed
in the above link
3. This represent the smallest amount of disk space allocated to hold a
file.
I feel this might not reduce your I/O.
4. No, Sp3a is the latest service pack.
Thanks
Hari
MCDBA
"Chip" <Chipsin007@.yahoo.com> wrote in message
news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> Hi Group,
> For some reasons I have to pull the SQL Server Production
> server out of network and reinstall from OS level. I have
> few queries about Backing up the SQL server Databases and
> choosing cluster size.
> 1. Do I need to Backup/detach the Master,MSDB databases
> along with User database to restore again when SQL server
> is installed again freshly?. MSDB just has two maintenance
> plans running.I fell that I can just take the backups of
> User databases as I have to restore them on fresh
> installation.
> 2. I am creating three arrays on this server
> C: RAID1 Array ( OS) - Array1
> D: RAID1 (SQL Tran logs files)- Array2
> D: RAID5E ( SQL Data files) - Array3
> While installing SQLServer I will choose Array3 for SQL
> system databases. How do i move the master.ldf msdb.ldf
> model.ldf temp.ldf to Array2 ? does detach/attach work for
> system databses?
> 3. I am choosing 8KB Cluster on NTFS instead of Default
> 4KB cluster, does this help in enhancing the access of 8K
> SQL database pages in terms of I/O?
> 4. Are there any patches/fixes released after
> SQLServer2000 Service Pack 3a?
> OS Windows 2000 Server SP4
> SQL Server 2000 Standard Edition
> IBM x250 dual PIII Xeon 700MHz
> 4GB RAM
> 18GB for OS on server
> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> Thanks for your patience
> Regards
> Chip
|||Hi Hari,
Thanks for the help! one more doubt.. When I install SQL
Server by default it will create Master,MSDB . How do i
get rid of them and attach the last backed up master
(.mdf,.ldf), MSDB(.mdf,.ldf).
I guess I have to login in singleuser mode, detach them,
overwrite with the backed up files then attach?
Please give me step by step ( you are always awesome in
dealing step by step)
Sincerely
Chip
>--Original Message--
>Hi,
>1. This link details you the steps to move the system
and user databases.
> http://www.support.microsoft.com/?id=224071
Moving SQL Server
>Databases to a New Location with Detach/Attach
> It is always good to move the Master and MSDB
databases to new server.
>But it is a must that you should move master database
> since it stores Server config, Logins
permissions..If you are
>notloading master all the database users chanin will be
lost.
>2. For Master database after starting sql server using
trace flag "-T3608"
>and use sp_detach_db and then copy to new drive and use
> sp_attach_db to attach Master database. For Tempdb
use ALTER DATBASE ..
>MODIFY FILE option. Both methodologies are detailed
> in the above link
>3. This represent the smallest amount of disk space
allocated to hold a[vbcol=seagreen]
>file.
> I feel this might not reduce your I/O.
>
>4. No, Sp3a is the latest service pack.
>Thanks
>Hari
>MCDBA
>
>"Chip" <Chipsin007@.yahoo.com> wrote in message
>news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
Production[vbcol=seagreen]
have[vbcol=seagreen]
and[vbcol=seagreen]
server[vbcol=seagreen]
maintenance[vbcol=seagreen]
for[vbcol=seagreen]
8K
>
>.
>
|||Moving databases and database files:
Moving SQL Server Databases
http://www.support.microsoft.com/?id=224071
Moving Databases between Servers
http://www.support.microsoft.com/?id=314546
Using WITH MOVE in a Restore to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465
How To Transfer Logins and Passwords Between SQL Servers
http://www.support.microsoft.com/?id=246133
Mapping Logins & SIDs after a Restore
http://www.support.microsoft.com/?id=298897
Utility to map users to the correct login
http://www.dbmaint.com/SyncSqlLogins.asp
How to Resolve Permission Issues When a Database Is Moved Between SQL Servers
http://www.support.microsoft.com/?id=240872
User Logon and/or Permission Errors After Restoring Dump
http://www.support.microsoft.com/?id=168001
Disaster Recovery Articles for SQL Server
http://www.support.microsoft.com/?id=307775
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...[vbcol=seagreen]
> Hi Hari,
> Thanks for the help! one more doubt.. When I install SQL
> Server by default it will create Master,MSDB . How do i
> get rid of them and attach the last backed up master
> (.mdf,.ldf), MSDB(.mdf,.ldf).
> I guess I have to login in singleuser mode, detach them,
> overwrite with the backed up files then attach?
> Please give me step by step ( you are always awesome in
> dealing step by step)
> Sincerely
> Chip
> and user databases.
> Moving SQL Server
> databases to new server.
> permissions..If you are
> lost.
> trace flag "-T3608"
> use ALTER DATBASE ..
> allocated to hold a
> Production
> have
> and
> server
> maintenance
> for
> 8K
|||Hi Tibor,
I have all the links you posted. In fact I saved them from
one of your post. What I was asking is.. When I install a
SQL Server, It will create Master, MSDB databases. How do
I get rid of them to restore/attach the backed up Master &
MSDB .
Regards
Chip
>--Original Message--
>Moving databases and database files:
>
>Moving SQL Server Databases
>http://www.support.microsoft.com/?id=224071
>Moving Databases between Servers
>http://www.support.microsoft.com/?id=314546
>Using WITH MOVE in a Restore to a New Location with
Detach/Attach
>http://support.microsoft.com/?id=221465
>How To Transfer Logins and Passwords Between SQL Servers
>http://www.support.microsoft.com/?id=246133
>Mapping Logins & SIDs after a Restore
>http://www.support.microsoft.com/?id=298897
>Utility to map users to the correct login
>http://www.dbmaint.com/SyncSqlLogins.asp
>How to Resolve Permission Issues When a Database Is Moved
Between SQL Servers
>http://www.support.microsoft.com/?id=240872
>User Logon and/or Permission Errors After Restoring Dump
>http://www.support.microsoft.com/?id=168001
>Disaster Recovery Articles for SQL Server
>http://www.support.microsoft.com/?id=307775
>
>--
>Tibor Karaszi, SQL Server MVP
>http://www.karaszi.com/sqlserver/default.asp
>
>"Chip" <anonymous@.discussions.microsoft.com> wrote in
message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...[vbcol=seagreen]
databases[vbcol=seagreen]
backups of[vbcol=seagreen]
SQL[vbcol=seagreen]
msdb.ldf[vbcol=seagreen]
work[vbcol=seagreen]
Default[vbcol=seagreen]
of
>
>.
>
|||That should be in the articles. You can restore MSDB as well as master. For master, you need to be in single
user mode in order to do a restore.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:3a2b01c429a2$ac8eb190$a001280a@.phx.gbl...[vbcol=seagreen]
> Hi Tibor,
> I have all the links you posted. In fact I saved them from
> one of your post. What I was asking is.. When I install a
> SQL Server, It will create Master, MSDB databases. How do
> I get rid of them to restore/attach the backed up Master &
> MSDB .
> Regards
> Chip
> Detach/Attach
> Between SQL Servers
> message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> databases
> backups of
> SQL
> msdb.ldf
> work
> Default
> of

Please answer my queries for fresh Installation

Hi Group,
For some reasons I have to pull the SQL Server Production
server out of network and reinstall from OS level. I have
few queries about Backing up the SQL server Databases and
choosing cluster size.
1. Do I need to Backup/detach the Master,MSDB databases
along with User database to restore again when SQL server
is installed again freshly?. MSDB just has two maintenance
plans running.I fell that I can just take the backups of
User databases as I have to restore them on fresh
installation.
2. I am creating three arrays on this server
C: RAID1 Array ( OS) - Array1
D: RAID1 (SQL Tran logs files)- Array2
D: RAID5E ( SQL Data files) - Array3
While installing SQLServer I will choose Array3 for SQL
system databases. How do i move the master.ldf msdb.ldf
model.ldf temp.ldf to Array2 ? does detach/attach work for
system databses?
3. I am choosing 8KB Cluster on NTFS instead of Default
4KB cluster, does this help in enhancing the access of 8K
SQL database pages in terms of I/O?
4. Are there any patches/fixes released after
SQLServer2000 Service Pack 3a?
OS Windows 2000 Server SP4
SQL Server 2000 Standard Edition
IBM x250 dual PIII Xeon 700MHz
4GB RAM
18GB for OS on server
1.4TB on IBM FAStT200 HA + EXP500 expansion.
Thanks for your patience
Regards
ChipHi,
1. This link details you the steps to move the system and user databases.
http://www.support.microsoft.com/?id=224071 Moving SQL Server
Databases to a New Location with Detach/Attach
It is always good to move the Master and MSDB databases to new server.
But it is a must that you should move master database
since it stores Server config, Logins permissions..If you are
notloading master all the database users chanin will be lost.
2. For Master database after starting sql server using trace flag "-T3608"
and use sp_detach_db and then copy to new drive and use
sp_attach_db to attach Master database. For Tempdb use ALTER DATBASE ..
MODIFY FILE option. Both methodologies are detailed
in the above link
3. This represent the smallest amount of disk space allocated to hold a
file.
I feel this might not reduce your I/O.
4. No, Sp3a is the latest service pack.
Thanks
Hari
MCDBA
"Chip" <Chipsin007@.yahoo.com> wrote in message
news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> Hi Group,
> For some reasons I have to pull the SQL Server Production
> server out of network and reinstall from OS level. I have
> few queries about Backing up the SQL server Databases and
> choosing cluster size.
> 1. Do I need to Backup/detach the Master,MSDB databases
> along with User database to restore again when SQL server
> is installed again freshly?. MSDB just has two maintenance
> plans running.I fell that I can just take the backups of
> User databases as I have to restore them on fresh
> installation.
> 2. I am creating three arrays on this server
> C: RAID1 Array ( OS) - Array1
> D: RAID1 (SQL Tran logs files)- Array2
> D: RAID5E ( SQL Data files) - Array3
> While installing SQLServer I will choose Array3 for SQL
> system databases. How do i move the master.ldf msdb.ldf
> model.ldf temp.ldf to Array2 ? does detach/attach work for
> system databses?
> 3. I am choosing 8KB Cluster on NTFS instead of Default
> 4KB cluster, does this help in enhancing the access of 8K
> SQL database pages in terms of I/O?
> 4. Are there any patches/fixes released after
> SQLServer2000 Service Pack 3a?
> OS Windows 2000 Server SP4
> SQL Server 2000 Standard Edition
> IBM x250 dual PIII Xeon 700MHz
> 4GB RAM
> 18GB for OS on server
> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> Thanks for your patience
> Regards
> Chip|||Hi Hari,
Thanks for the help! one more doubt.. When I install SQL
Server by default it will create Master,MSDB . How do i
get rid of them and attach the last backed up master
(.mdf,.ldf), MSDB(.mdf,.ldf).
I guess I have to login in singleuser mode, detach them,
overwrite with the backed up files then attach?
Please give me step by step ( you are always awesome in
dealing step by step)
Sincerely
Chip
>--Original Message--
>Hi,
>1. This link details you the steps to move the system
and user databases.
> http://www.support.microsoft.com/?id=224071
Moving SQL Server
>Databases to a New Location with Detach/Attach
> It is always good to move the Master and MSDB
databases to new server.
>But it is a must that you should move master database
> since it stores Server config, Logins
permissions..If you are
>notloading master all the database users chanin will be
lost.
>2. For Master database after starting sql server using
trace flag "-T3608"
>and use sp_detach_db and then copy to new drive and use
> sp_attach_db to attach Master database. For Tempdb
use ALTER DATBASE ..
>MODIFY FILE option. Both methodologies are detailed
> in the above link
>3. This represent the smallest amount of disk space
allocated to hold a
>file.
> I feel this might not reduce your I/O.
>
>4. No, Sp3a is the latest service pack.
>Thanks
>Hari
>MCDBA
>
>"Chip" <Chipsin007@.yahoo.com> wrote in message
>news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
>> Hi Group,
>> For some reasons I have to pull the SQL Server
Production
>> server out of network and reinstall from OS level. I
have
>> few queries about Backing up the SQL server Databases
and
>> choosing cluster size.
>> 1. Do I need to Backup/detach the Master,MSDB databases
>> along with User database to restore again when SQL
server
>> is installed again freshly?. MSDB just has two
maintenance
>> plans running.I fell that I can just take the backups of
>> User databases as I have to restore them on fresh
>> installation.
>> 2. I am creating three arrays on this server
>> C: RAID1 Array ( OS) - Array1
>> D: RAID1 (SQL Tran logs files)- Array2
>> D: RAID5E ( SQL Data files) - Array3
>> While installing SQLServer I will choose Array3 for SQL
>> system databases. How do i move the master.ldf msdb.ldf
>> model.ldf temp.ldf to Array2 ? does detach/attach work
for
>> system databses?
>> 3. I am choosing 8KB Cluster on NTFS instead of Default
>> 4KB cluster, does this help in enhancing the access of
8K
>> SQL database pages in terms of I/O?
>> 4. Are there any patches/fixes released after
>> SQLServer2000 Service Pack 3a?
>> OS Windows 2000 Server SP4
>> SQL Server 2000 Standard Edition
>> IBM x250 dual PIII Xeon 700MHz
>> 4GB RAM
>> 18GB for OS on server
>> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
>> Thanks for your patience
>> Regards
>> Chip
>
>.
>|||Moving databases and database files:
Moving SQL Server Databases
http://www.support.microsoft.com/?id=224071
Moving Databases between Servers
http://www.support.microsoft.com/?id=314546
Using WITH MOVE in a Restore to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465
How To Transfer Logins and Passwords Between SQL Servers
http://www.support.microsoft.com/?id=246133
Mapping Logins & SIDs after a Restore
http://www.support.microsoft.com/?id=298897
Utility to map users to the correct login
http://www.dbmaint.com/SyncSqlLogins.asp
How to Resolve Permission Issues When a Database Is Moved Between SQL Servers
http://www.support.microsoft.com/?id=240872
User Logon and/or Permission Errors After Restoring Dump
http://www.support.microsoft.com/?id=168001
Disaster Recovery Articles for SQL Server
http://www.support.microsoft.com/?id=307775
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> Hi Hari,
> Thanks for the help! one more doubt.. When I install SQL
> Server by default it will create Master,MSDB . How do i
> get rid of them and attach the last backed up master
> (.mdf,.ldf), MSDB(.mdf,.ldf).
> I guess I have to login in singleuser mode, detach them,
> overwrite with the backed up files then attach?
> Please give me step by step ( you are always awesome in
> dealing step by step)
> Sincerely
> Chip
> >--Original Message--
> >Hi,
> >
> >1. This link details you the steps to move the system
> and user databases.
> > http://www.support.microsoft.com/?id=224071
> Moving SQL Server
> >Databases to a New Location with Detach/Attach
> > It is always good to move the Master and MSDB
> databases to new server.
> >But it is a must that you should move master database
> > since it stores Server config, Logins
> permissions..If you are
> >notloading master all the database users chanin will be
> lost.
> >
> >2. For Master database after starting sql server using
> trace flag "-T3608"
> >and use sp_detach_db and then copy to new drive and use
> > sp_attach_db to attach Master database. For Tempdb
> use ALTER DATBASE ..
> >MODIFY FILE option. Both methodologies are detailed
> > in the above link
> >
> >3. This represent the smallest amount of disk space
> allocated to hold a
> >file.
> > I feel this might not reduce your I/O.
> >
> >
> >4. No, Sp3a is the latest service pack.
> >
> >Thanks
> >Hari
> >MCDBA
> >
> >
> >
> >"Chip" <Chipsin007@.yahoo.com> wrote in message
> >news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> >> Hi Group,
> >>
> >> For some reasons I have to pull the SQL Server
> Production
> >> server out of network and reinstall from OS level. I
> have
> >> few queries about Backing up the SQL server Databases
> and
> >> choosing cluster size.
> >>
> >> 1. Do I need to Backup/detach the Master,MSDB databases
> >> along with User database to restore again when SQL
> server
> >> is installed again freshly?. MSDB just has two
> maintenance
> >> plans running.I fell that I can just take the backups of
> >> User databases as I have to restore them on fresh
> >> installation.
> >>
> >> 2. I am creating three arrays on this server
> >> C: RAID1 Array ( OS) - Array1
> >> D: RAID1 (SQL Tran logs files)- Array2
> >> D: RAID5E ( SQL Data files) - Array3
> >>
> >> While installing SQLServer I will choose Array3 for SQL
> >> system databases. How do i move the master.ldf msdb.ldf
> >> model.ldf temp.ldf to Array2 ? does detach/attach work
> for
> >> system databses?
> >>
> >> 3. I am choosing 8KB Cluster on NTFS instead of Default
> >> 4KB cluster, does this help in enhancing the access of
> 8K
> >> SQL database pages in terms of I/O?
> >>
> >> 4. Are there any patches/fixes released after
> >> SQLServer2000 Service Pack 3a?
> >>
> >> OS Windows 2000 Server SP4
> >> SQL Server 2000 Standard Edition
> >> IBM x250 dual PIII Xeon 700MHz
> >> 4GB RAM
> >> 18GB for OS on server
> >> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> >>
> >> Thanks for your patience
> >>
> >> Regards
> >>
> >> Chip
> >
> >
> >.
> >|||Hi Tibor,
I have all the links you posted. In fact I saved them from
one of your post. What I was asking is.. When I install a
SQL Server, It will create Master, MSDB databases. How do
I get rid of them to restore/attach the backed up Master &
MSDB .
Regards
Chip
>--Original Message--
>Moving databases and database files:
>
>Moving SQL Server Databases
>http://www.support.microsoft.com/?id=224071
>Moving Databases between Servers
>http://www.support.microsoft.com/?id=314546
>Using WITH MOVE in a Restore to a New Location with
Detach/Attach
>http://support.microsoft.com/?id=221465
>How To Transfer Logins and Passwords Between SQL Servers
>http://www.support.microsoft.com/?id=246133
>Mapping Logins & SIDs after a Restore
>http://www.support.microsoft.com/?id=298897
>Utility to map users to the correct login
>http://www.dbmaint.com/SyncSqlLogins.asp
>How to Resolve Permission Issues When a Database Is Moved
Between SQL Servers
>http://www.support.microsoft.com/?id=240872
>User Logon and/or Permission Errors After Restoring Dump
>http://www.support.microsoft.com/?id=168001
>Disaster Recovery Articles for SQL Server
>http://www.support.microsoft.com/?id=307775
>
>--
>Tibor Karaszi, SQL Server MVP
>http://www.karaszi.com/sqlserver/default.asp
>
>"Chip" <anonymous@.discussions.microsoft.com> wrote in
message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
>> Hi Hari,
>> Thanks for the help! one more doubt.. When I install SQL
>> Server by default it will create Master,MSDB . How do i
>> get rid of them and attach the last backed up master
>> (.mdf,.ldf), MSDB(.mdf,.ldf).
>> I guess I have to login in singleuser mode, detach them,
>> overwrite with the backed up files then attach?
>> Please give me step by step ( you are always awesome in
>> dealing step by step)
>> Sincerely
>> Chip
>> >--Original Message--
>> >Hi,
>> >
>> >1. This link details you the steps to move the system
>> and user databases.
>> > http://www.support.microsoft.com/?id=224071
>> Moving SQL Server
>> >Databases to a New Location with Detach/Attach
>> > It is always good to move the Master and MSDB
>> databases to new server.
>> >But it is a must that you should move master database
>> > since it stores Server config, Logins
>> permissions..If you are
>> >notloading master all the database users chanin will be
>> lost.
>> >
>> >2. For Master database after starting sql server using
>> trace flag "-T3608"
>> >and use sp_detach_db and then copy to new drive and use
>> > sp_attach_db to attach Master database. For Tempdb
>> use ALTER DATBASE ..
>> >MODIFY FILE option. Both methodologies are detailed
>> > in the above link
>> >
>> >3. This represent the smallest amount of disk space
>> allocated to hold a
>> >file.
>> > I feel this might not reduce your I/O.
>> >
>> >
>> >4. No, Sp3a is the latest service pack.
>> >
>> >Thanks
>> >Hari
>> >MCDBA
>> >
>> >
>> >
>> >"Chip" <Chipsin007@.yahoo.com> wrote in message
>> >news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
>> >> Hi Group,
>> >>
>> >> For some reasons I have to pull the SQL Server
>> Production
>> >> server out of network and reinstall from OS level. I
>> have
>> >> few queries about Backing up the SQL server Databases
>> and
>> >> choosing cluster size.
>> >>
>> >> 1. Do I need to Backup/detach the Master,MSDB
databases
>> >> along with User database to restore again when SQL
>> server
>> >> is installed again freshly?. MSDB just has two
>> maintenance
>> >> plans running.I fell that I can just take the
backups of
>> >> User databases as I have to restore them on fresh
>> >> installation.
>> >>
>> >> 2. I am creating three arrays on this server
>> >> C: RAID1 Array ( OS) - Array1
>> >> D: RAID1 (SQL Tran logs files)- Array2
>> >> D: RAID5E ( SQL Data files) - Array3
>> >>
>> >> While installing SQLServer I will choose Array3 for
SQL
>> >> system databases. How do i move the master.ldf
msdb.ldf
>> >> model.ldf temp.ldf to Array2 ? does detach/attach
work
>> for
>> >> system databses?
>> >>
>> >> 3. I am choosing 8KB Cluster on NTFS instead of
Default
>> >> 4KB cluster, does this help in enhancing the access
of
>> 8K
>> >> SQL database pages in terms of I/O?
>> >>
>> >> 4. Are there any patches/fixes released after
>> >> SQLServer2000 Service Pack 3a?
>> >>
>> >> OS Windows 2000 Server SP4
>> >> SQL Server 2000 Standard Edition
>> >> IBM x250 dual PIII Xeon 700MHz
>> >> 4GB RAM
>> >> 18GB for OS on server
>> >> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
>> >>
>> >> Thanks for your patience
>> >>
>> >> Regards
>> >>
>> >> Chip
>> >
>> >
>> >.
>> >
>
>.
>|||That should be in the articles. You can restore MSDB as well as master. For master, you need to be in single
user mode in order to do a restore.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:3a2b01c429a2$ac8eb190$a001280a@.phx.gbl...
> Hi Tibor,
> I have all the links you posted. In fact I saved them from
> one of your post. What I was asking is.. When I install a
> SQL Server, It will create Master, MSDB databases. How do
> I get rid of them to restore/attach the backed up Master &
> MSDB .
> Regards
> Chip
> >--Original Message--
> >Moving databases and database files:
> >
> >
> >Moving SQL Server Databases
> >http://www.support.microsoft.com/?id=224071
> >
> >Moving Databases between Servers
> >http://www.support.microsoft.com/?id=314546
> >
> >Using WITH MOVE in a Restore to a New Location with
> Detach/Attach
> >http://support.microsoft.com/?id=221465
> >
> >How To Transfer Logins and Passwords Between SQL Servers
> >http://www.support.microsoft.com/?id=246133
> >
> >Mapping Logins & SIDs after a Restore
> >http://www.support.microsoft.com/?id=298897
> >
> >Utility to map users to the correct login
> >http://www.dbmaint.com/SyncSqlLogins.asp
> >
> >How to Resolve Permission Issues When a Database Is Moved
> Between SQL Servers
> >http://www.support.microsoft.com/?id=240872
> >
> >User Logon and/or Permission Errors After Restoring Dump
> >http://www.support.microsoft.com/?id=168001
> >
> >Disaster Recovery Articles for SQL Server
> >http://www.support.microsoft.com/?id=307775
> >
> >
> >--
> >Tibor Karaszi, SQL Server MVP
> >http://www.karaszi.com/sqlserver/default.asp
> >
> >
> >"Chip" <anonymous@.discussions.microsoft.com> wrote in
> message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> >> Hi Hari,
> >>
> >> Thanks for the help! one more doubt.. When I install SQL
> >> Server by default it will create Master,MSDB . How do i
> >> get rid of them and attach the last backed up master
> >> (.mdf,.ldf), MSDB(.mdf,.ldf).
> >>
> >> I guess I have to login in singleuser mode, detach them,
> >> overwrite with the backed up files then attach?
> >>
> >> Please give me step by step ( you are always awesome in
> >> dealing step by step)
> >>
> >> Sincerely
> >>
> >> Chip
> >> >--Original Message--
> >> >Hi,
> >> >
> >> >1. This link details you the steps to move the system
> >> and user databases.
> >> > http://www.support.microsoft.com/?id=224071
> >> Moving SQL Server
> >> >Databases to a New Location with Detach/Attach
> >> > It is always good to move the Master and MSDB
> >> databases to new server.
> >> >But it is a must that you should move master database
> >> > since it stores Server config, Logins
> >> permissions..If you are
> >> >notloading master all the database users chanin will be
> >> lost.
> >> >
> >> >2. For Master database after starting sql server using
> >> trace flag "-T3608"
> >> >and use sp_detach_db and then copy to new drive and use
> >> > sp_attach_db to attach Master database. For Tempdb
> >> use ALTER DATBASE ..
> >> >MODIFY FILE option. Both methodologies are detailed
> >> > in the above link
> >> >
> >> >3. This represent the smallest amount of disk space
> >> allocated to hold a
> >> >file.
> >> > I feel this might not reduce your I/O.
> >> >
> >> >
> >> >4. No, Sp3a is the latest service pack.
> >> >
> >> >Thanks
> >> >Hari
> >> >MCDBA
> >> >
> >> >
> >> >
> >> >"Chip" <Chipsin007@.yahoo.com> wrote in message
> >> >news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> >> >> Hi Group,
> >> >>
> >> >> For some reasons I have to pull the SQL Server
> >> Production
> >> >> server out of network and reinstall from OS level. I
> >> have
> >> >> few queries about Backing up the SQL server Databases
> >> and
> >> >> choosing cluster size.
> >> >>
> >> >> 1. Do I need to Backup/detach the Master,MSDB
> databases
> >> >> along with User database to restore again when SQL
> >> server
> >> >> is installed again freshly?. MSDB just has two
> >> maintenance
> >> >> plans running.I fell that I can just take the
> backups of
> >> >> User databases as I have to restore them on fresh
> >> >> installation.
> >> >>
> >> >> 2. I am creating three arrays on this server
> >> >> C: RAID1 Array ( OS) - Array1
> >> >> D: RAID1 (SQL Tran logs files)- Array2
> >> >> D: RAID5E ( SQL Data files) - Array3
> >> >>
> >> >> While installing SQLServer I will choose Array3 for
> SQL
> >> >> system databases. How do i move the master.ldf
> msdb.ldf
> >> >> model.ldf temp.ldf to Array2 ? does detach/attach
> work
> >> for
> >> >> system databses?
> >> >>
> >> >> 3. I am choosing 8KB Cluster on NTFS instead of
> Default
> >> >> 4KB cluster, does this help in enhancing the access
> of
> >> 8K
> >> >> SQL database pages in terms of I/O?
> >> >>
> >> >> 4. Are there any patches/fixes released after
> >> >> SQLServer2000 Service Pack 3a?
> >> >>
> >> >> OS Windows 2000 Server SP4
> >> >> SQL Server 2000 Standard Edition
> >> >> IBM x250 dual PIII Xeon 700MHz
> >> >> 4GB RAM
> >> >> 18GB for OS on server
> >> >> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> >> >>
> >> >> Thanks for your patience
> >> >>
> >> >> Regards
> >> >>
> >> >> Chip
> >> >
> >> >
> >> >.
> >> >
> >
> >
> >.
> >sql

Please answer my queries for fresh Installation

Hi Group,
For some reasons I have to pull the SQL Server Production
server out of network and reinstall from OS level. I have
few queries about Backing up the SQL server Databases and
choosing cluster size.
1. Do I need to Backup/detach the Master,MSDB databases
along with User database to restore again when SQL server
is installed again freshly?. MSDB just has two maintenance
plans running.I fell that I can just take the backups of
User databases as I have to restore them on fresh
installation.
2. I am creating three arrays on this server
C: RAID1 Array ( OS) - Array1
D: RAID1 (SQL Tran logs files)- Array2
D: RAID5E ( SQL Data files) - Array3
While installing SQLServer I will choose Array3 for SQL
system databases. How do i move the master.ldf msdb.ldf
model.ldf temp.ldf to Array2 ? does detach/attach work for
system databses?
3. I am choosing 8KB Cluster on NTFS instead of Default
4KB cluster, does this help in enhancing the access of 8K
SQL database pages in terms of I/O?
4. Are there any patches/fixes released after
SQLServer2000 Service Pack 3a?
OS Windows 2000 Server SP4
SQL Server 2000 Standard Edition
IBM x250 dual PIII Xeon 700MHz
4GB RAM
18GB for OS on server
1.4TB on IBM FAStT200 HA + EXP500 expansion.
Thanks for your patience
Regards
ChipHi,
1. This link details you the steps to move the system and user databases.
http://www.support.microsoft.com/?id=224071 Moving SQL Server
Databases to a New Location with Detach/Attach
It is always good to move the Master and MSDB databases to new server.
But it is a must that you should move master database
since it stores Server config, Logins permissions..If you are
notloading master all the database users chanin will be lost.
2. For Master database after starting sql server using trace flag "-T3608"
and use sp_detach_db and then copy to new drive and use
sp_attach_db to attach Master database. For Tempdb use ALTER DATBASE ..
MODIFY FILE option. Both methodologies are detailed
in the above link
3. This represent the smallest amount of disk space allocated to hold a
file.
I feel this might not reduce your I/O.
4. No, Sp3a is the latest service pack.
Thanks
Hari
MCDBA
"Chip" <Chipsin007@.yahoo.com> wrote in message
news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
> Hi Group,
> For some reasons I have to pull the SQL Server Production
> server out of network and reinstall from OS level. I have
> few queries about Backing up the SQL server Databases and
> choosing cluster size.
> 1. Do I need to Backup/detach the Master,MSDB databases
> along with User database to restore again when SQL server
> is installed again freshly?. MSDB just has two maintenance
> plans running.I fell that I can just take the backups of
> User databases as I have to restore them on fresh
> installation.
> 2. I am creating three arrays on this server
> C: RAID1 Array ( OS) - Array1
> D: RAID1 (SQL Tran logs files)- Array2
> D: RAID5E ( SQL Data files) - Array3
> While installing SQLServer I will choose Array3 for SQL
> system databases. How do i move the master.ldf msdb.ldf
> model.ldf temp.ldf to Array2 ? does detach/attach work for
> system databses?
> 3. I am choosing 8KB Cluster on NTFS instead of Default
> 4KB cluster, does this help in enhancing the access of 8K
> SQL database pages in terms of I/O?
> 4. Are there any patches/fixes released after
> SQLServer2000 Service Pack 3a?
> OS Windows 2000 Server SP4
> SQL Server 2000 Standard Edition
> IBM x250 dual PIII Xeon 700MHz
> 4GB RAM
> 18GB for OS on server
> 1.4TB on IBM FAStT200 HA + EXP500 expansion.
> Thanks for your patience
> Regards
> Chip|||Hi Hari,
Thanks for the help! one more doubt.. When I install SQL
Server by default it will create Master,MSDB . How do i
get rid of them and attach the last backed up master
(.mdf,.ldf), MSDB(.mdf,.ldf).
I guess I have to login in singleuser mode, detach them,
overwrite with the backed up files then attach?
Please give me step by step ( you are always awesome in
dealing step by step)
Sincerely
Chip
>--Original Message--
>Hi,
>1. This link details you the steps to move the system
and user databases.
> http://www.support.microsoft.com/?id=224071
Moving SQL Server
>Databases to a New Location with Detach/Attach
> It is always good to move the Master and MSDB
databases to new server.
>But it is a must that you should move master database
> since it stores Server config, Logins
permissions..If you are
>notloading master all the database users chanin will be
lost.
>2. For Master database after starting sql server using
trace flag "-T3608"
>and use sp_detach_db and then copy to new drive and use
> sp_attach_db to attach Master database. For Tempdb
use ALTER DATBASE ..
>MODIFY FILE option. Both methodologies are detailed
> in the above link
>3. This represent the smallest amount of disk space
allocated to hold a
>file.
> I feel this might not reduce your I/O.
>
>4. No, Sp3a is the latest service pack.
>Thanks
>Hari
>MCDBA
>
>"Chip" <Chipsin007@.yahoo.com> wrote in message
>news:32b801c4290c$a0a01a90$a501280a@.phx.gbl...
Production[vbcol=seagreen]
have[vbcol=seagreen]
and[vbcol=seagreen]
server[vbcol=seagreen]
maintenance[vbcol=seagreen]
for[vbcol=seagreen]
8K[vbcol=seagreen]
>
>.
>|||Moving databases and database files:
Moving SQL Server Databases
http://www.support.microsoft.com/?id=224071
Moving Databases between Servers
http://www.support.microsoft.com/?id=314546
Using WITH MOVE in a Restore to a New Location with Detach/Attach
http://support.microsoft.com/?id=221465
How To Transfer Logins and Passwords Between SQL Servers
http://www.support.microsoft.com/?id=246133
Mapping Logins & SIDs after a Restore
http://www.support.microsoft.com/?id=298897
Utility to map users to the correct login
http://www.dbmaint.com/SyncSqlLogins.asp
How to Resolve Permission Issues When a Database Is Moved Between SQL Server
s
http://www.support.microsoft.com/?id=240872
User Logon and/or Permission Errors After Restoring Dump
http://www.support.microsoft.com/?id=168001
Disaster Recovery Articles for SQL Server
http://www.support.microsoft.com/?id=307775
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:34a801c4292b$29db0a90$a00
1280a@.phx.gbl...[vbcol=seagreen]
> Hi Hari,
> Thanks for the help! one more doubt.. When I install SQL
> Server by default it will create Master,MSDB . How do i
> get rid of them and attach the last backed up master
> (.mdf,.ldf), MSDB(.mdf,.ldf).
> I guess I have to login in singleuser mode, detach them,
> overwrite with the backed up files then attach?
> Please give me step by step ( you are always awesome in
> dealing step by step)
> Sincerely
> Chip
> and user databases.
> Moving SQL Server
> databases to new server.
> permissions..If you are
> lost.
> trace flag "-T3608"
> use ALTER DATBASE ..
> allocated to hold a
> Production
> have
> and
> server
> maintenance
> for
> 8K|||Hi Tibor,
I have all the links you posted. In fact I saved them from
one of your post. What I was asking is.. When I install a
SQL Server, It will create Master, MSDB databases. How do
I get rid of them to restore/attach the backed up Master &
MSDB .
Regards
Chip
>--Original Message--
>Moving databases and database files:
>
>Moving SQL Server Databases
>http://www.support.microsoft.com/?id=224071
>Moving Databases between Servers
>http://www.support.microsoft.com/?id=314546
>Using WITH MOVE in a Restore to a New Location with
Detach/Attach
>http://support.microsoft.com/?id=221465
>How To Transfer Logins and Passwords Between SQL Servers
>http://www.support.microsoft.com/?id=246133
>Mapping Logins & SIDs after a Restore
>http://www.support.microsoft.com/?id=298897
>Utility to map users to the correct login
>http://www.dbmaint.com/SyncSqlLogins.asp
>How to Resolve Permission Issues When a Database Is Moved
Between SQL Servers
>http://www.support.microsoft.com/?id=240872
>User Logon and/or Permission Errors After Restoring Dump
>http://www.support.microsoft.com/?id=168001
>Disaster Recovery Articles for SQL Server
>http://www.support.microsoft.com/?id=307775
>
>--
>Tibor Karaszi, SQL Server MVP
>http://www.karaszi.com/sqlserver/default.asp
>
>"Chip" <anonymous@.discussions.microsoft.com> wrote in
message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
databases[vbcol=seagreen]
backups of[vbcol=seagreen]
SQL[vbcol=seagreen]
msdb.ldf[vbcol=seagreen]
work[vbcol=seagreen]
Default[vbcol=seagreen]
of[vbcol=seagreen]
>
>.
>|||That should be in the articles. You can restore MSDB as well as master. For
master, you need to be in single
user mode in order to do a restore.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
"Chip" <anonymous@.discussions.microsoft.com> wrote in message news:3a2b01c429a2$ac8eb190$a00
1280a@.phx.gbl...[vbcol=seagreen]
> Hi Tibor,
> I have all the links you posted. In fact I saved them from
> one of your post. What I was asking is.. When I install a
> SQL Server, It will create Master, MSDB databases. How do
> I get rid of them to restore/attach the backed up Master &
> MSDB .
> Regards
> Chip
> Detach/Attach
> Between SQL Servers
> message news:34a801c4292b$29db0a90$a001280a@.phx.gbl...
> databases
> backups of
> SQL
> msdb.ldf
> work
> Default
> of

Monday, March 12, 2012

Place or book to test writing T-SQL queries?

Hi,
I am looking for a place where I get to write sql queries and test my sql knowledge.If any one can suggest me site or book where I can test my sql knowledge. I have good exposure of SQL syntax and want to test how I implement it. Also, If Forum moderator can suggest me any book on this to improve myself in T-SQL.

Regards

Download the FREE copy of SQL Server 2005 Express, and use it to test your code on your local computer. Get your copy here.

For books, look at BOTH volumes of Itzak Ben-Gan's Microsoft Press titles.

|||Jump start to test your SQL skills...
http://www.sql-ex.ru/

|||Is there any book that provides sample scenarios for which one can write queries , like questions handbook? I do not have access to web all time, so , was looking for some offline solution. My requirement is getting some real life scenario query making.|||

SQL Server Express is installed locally on your computer, so it can be used whether or not you're connected to the web.

That will give you the environment in which to practice.

As to what to practice, try one of the Celko "puzzle" books or the SQL Server 2005: Applied techniques Step By Step book.

A search on Amazon.com for beginning SQL Server will also give you some possibilities.

Additionally, come to this forum, or any other sql forum where people post questions looking for help, and work on solving their issue(s).

(Even if someone else has provided a solution, disregard that solution while you work on coming up with your own and then check to see what others came up with.)

Saturday, February 25, 2012

Pivot Tables and MDX

Hi!
I want to write some MDX queries that pull the same data I'm retriving into
an excel pivot table that is hitting my cube. Up front, I'm pretty sure thi
s is not doable, but need to ask anyway. I want some way of hooking into th
e MSOLAP provider to see th
e MDX that's generated and sent to analysis services to retrieve the data in
to the pivot table. This would be an excellent shortcut to getting my MDX q
uery results to match what I'm getting in the pivot table.
Any anyone know of a way to see the MDX that's being generated from the pivo
t table?
-thanksInclude property Log File in your connection string.
Log File="C:\work\Sales_stock\mdx\excel_log\log.txt"
in log.txt you will find mdx queries.
Ramunas Balukonis
"brian p" <anonymous@.discussions.microsoft.com> wrote in message
news:399BECD7-270E-4539-BAC0-C628EB09D2B8@.microsoft.com...
> Hi!
> I want to write some MDX queries that pull the same data I'm retriving
into an excel pivot table that is hitting my cube. Up front, I'm pretty
sure this is not doable, but need to ask anyway. I want some way of hooking
into the MSOLAP provider to see the MDX that's generated and sent to
analysis services to retrieve the data into the pivot table. This would be
an excellent shortcut to getting my MDX query results to match what I'm
getting in the pivot table.
> Any anyone know of a way to see the MDX that's being generated from the
pivot table?
> -thanks

Monday, February 20, 2012

Pivot Query or Cross Tab queries

I can't seem to figure out how to create a cross tab or pivot query on data.
If I was writing the SQL in Access I would write it like
TRANSFORM SUM(DTL.Amount) AS Amount
SELECT
STC.ClientID
, STC.Client
, STC.SS_ID
, STC.Region
, STC.[Sales Director]
, STC.[Product Consultant]
, STC.CCC
FROM (SELECT
STC.DW_SELLER_ID AS ClientID
, STC.SELLER_NAME AS Client
, STC.SS_ID
, STC.TEAM_ACQ_NAME AS Region
, STC.ACCOUNT_MANAGER_NAME AS [Sales Director]
, STC.[Product Consultant]
, CTC.CLIENT_CENTRIC_CATEGORY_DSCR AS CCC
FROM dbo.tSeller_Team_Current AS STC
LEFT JOIN OPENQUERY(SSOT_DWDB,
'SELECT DW_CLIENT_ID, CLIENT_CENTRIC_CATEGORY_DSCR
FROM DW.DW_SALES_CLIENT_TEAM_CURR') AS CTC
ON STC.DW_SELLER_ID = CTC.DW_CLIENT_ID
WHERE STC.Channel='RF'
AND STC.SELLER_ACTIVATION_DATE Is Not Null
AND SELLER_CLOSED_DATE Is Null) AS STC
LEFT JOIN dbo.tCRC_Details AS DTL
ON STC.ClientID=DTL.ClientID
GROUP BY
STC.ClientID
, STC.Client
, STC.SS_ID
, STC.Region
, STC.[Sales Director]
, STC.[Product Consultant]
, STC.CCC
PIVOT DTL.[Description]
How could I write the query so it works in a View?
Thanks in advance.
Mark
I don't believe you can do crosstab queries within SQL Server like you can
in Access
"MChrist" <MChrist@.discussions.microsoft.com> wrote in message
news:C5FE6FA4-8AB9-49DE-BA7F-1BD0F226B01A@.microsoft.com...
>I can't seem to figure out how to create a cross tab or pivot query on
>data.
> If I was writing the SQL in Access I would write it like
> TRANSFORM SUM(DTL.Amount) AS Amount
> SELECT
> STC.ClientID
> , STC.Client
> , STC.SS_ID
> , STC.Region
> , STC.[Sales Director]
> , STC.[Product Consultant]
> , STC.CCC
> FROM (SELECT
> STC.DW_SELLER_ID AS ClientID
> , STC.SELLER_NAME AS Client
> , STC.SS_ID
> , STC.TEAM_ACQ_NAME AS Region
> , STC.ACCOUNT_MANAGER_NAME AS [Sales Director]
> , STC.[Product Consultant]
> , CTC.CLIENT_CENTRIC_CATEGORY_DSCR AS CCC
> FROM dbo.tSeller_Team_Current AS STC
> LEFT JOIN OPENQUERY(SSOT_DWDB,
> 'SELECT DW_CLIENT_ID, CLIENT_CENTRIC_CATEGORY_DSCR
> FROM DW.DW_SALES_CLIENT_TEAM_CURR') AS CTC
> ON STC.DW_SELLER_ID = CTC.DW_CLIENT_ID
> WHERE STC.Channel='RF'
> AND STC.SELLER_ACTIVATION_DATE Is Not Null
> AND SELLER_CLOSED_DATE Is Null) AS STC
> LEFT JOIN dbo.tCRC_Details AS DTL
> ON STC.ClientID=DTL.ClientID
> GROUP BY
> STC.ClientID
> , STC.Client
> , STC.SS_ID
> , STC.Region
> , STC.[Sales Director]
> , STC.[Product Consultant]
> , STC.CCC
> PIVOT DTL.[Description]
> How could I write the query so it works in a View?
> Thanks in advance.
> Mark
>
|||Thanks for your response Al. After scoping books and the help for several
hours that's the conclusion I came to also. Strange how the little baby
brother can do something that big brother can't. But that's as consistent as
the use of functions and naming conventions across MS software.
Have a great weekend.
Mark
"Al Newbie" wrote:

> I don't believe you can do crosstab queries within SQL Server like you can
> in Access
> "MChrist" <MChrist@.discussions.microsoft.com> wrote in message
> news:C5FE6FA4-8AB9-49DE-BA7F-1BD0F226B01A@.microsoft.com...
>
>

pivot information

Hi there,
I haven't used queries to put data in columns in quite some time, so I'm
slightly rusty... I would appreciate some help with the following please:
(SQL 2000)
Query:
select [Date], MachNo,
case when Shift = 'A' then sum(Quantity) else 0 end as ShiftAQty,
case when Shift = 'B' then sum(Quantity) else 0 end as ShiftBQty,
case when Shift = 'C' then sum(Quantity) else 0 end as ShiftCQty
from Prod_Knitting_Data_1
group by [Date], MachNo, Shift
Result (extract):
Date Mc A B C
2008-01-07 00:00:00.000 01 0 0 400
2008-01-07 00:00:00.000 01 0 200 0
2008-01-07 00:00:00.000 02 0 0 0
2008-01-07 00:00:00.000 02 0 120 0
2008-01-07 00:00:00.000 03 0 0 180
2008-01-07 00:00:00.000 03 0 180 0
2008-01-07 00:00:00.000 03 60 0 0
As can be seen I need the results to be in one row for each date, machine
I know I'm missing something... but cannot recall what...
Thank you in advance!
Change the query to take the SUM out of the CASE function:
SELECT [Date], MachNo,
SUM(CASE WHEN Shift = 'A' THEN Quantity ELSE 0 END) AS
ShiftAQty,
SUM(CASE WHEN Shift = 'B' THEN Quantity ELSE 0 END) AS
ShiftBQty,
SUM(CASE WHEN Shift = 'C' THEN Quantity ELSE 0 END) AS ShiftCQty
FROM Prod_Knitting_Data_1
GROUP BY [Date], MachNo
HTH,
Plamen Ratchev
E-Mail: Plamen@.Ratchev.com
|||select [Date], MachNo,
sum(case when Shift = 'A' then Quantity else 0 end) as
ShiftAQty,
sum(case when Shift = 'B' then Quantity else 0 end) as
ShiftBQty,
sum(case when Shift = 'C' then Quantity else 0 end) as
ShiftCQty,
from Prod_Knitting_Data_1
group by [Date], MachNo
"PsyberFox" <PsyberFox@.discussions.microsoft.com> wrote in message
news:21D07D5F-6113-403F-8E6D-FBB4F433DEFB@.microsoft.com...
> Hi there,
> I haven't used queries to put data in columns in quite some time, so I'm
> slightly rusty... I would appreciate some help with the following please:
> (SQL 2000)
> Query:
> select [Date], MachNo,
> case when Shift = 'A' then sum(Quantity) else 0 end as
> ShiftAQty,
> case when Shift = 'B' then sum(Quantity) else 0 end as
> ShiftBQty,
> case when Shift = 'C' then sum(Quantity) else 0 end as
> ShiftCQty
> from Prod_Knitting_Data_1
> group by [Date], MachNo, Shift
>
> Result (extract):
> Date Mc A B C
> 2008-01-07 00:00:00.000 01 0 0 400
> 2008-01-07 00:00:00.000 01 0 200 0
> 2008-01-07 00:00:00.000 02 0 0 0
> 2008-01-07 00:00:00.000 02 0 120 0
> 2008-01-07 00:00:00.000 03 0 0 180
> 2008-01-07 00:00:00.000 03 0 180 0
> 2008-01-07 00:00:00.000 03 60 0 0
>
> As can be seen I need the results to be in one row for each date, machine
> I know I'm missing something... but cannot recall what...
> Thank you in advance!

pivot information

Hi there,
I haven't used queries to put data in columns in quite some time, so I'm
slightly rusty... I would appreciate some help with the following please:
(SQL 2000)
Query:
select [Date], MachNo,
case when Shift = 'A' then sum(Quantity) else 0 end as ShiftAQty,
case when Shift = 'B' then sum(Quantity) else 0 end as ShiftBQty,
case when Shift = 'C' then sum(Quantity) else 0 end as ShiftCQty
from Prod_Knitting_Data_1
group by [Date], MachNo, Shift
Result (extract):
Date Mc A B C
2008-01-07 00:00:00.000 01 0 0 400
2008-01-07 00:00:00.000 01 0 200 0
2008-01-07 00:00:00.000 02 0 0 0
2008-01-07 00:00:00.000 02 0 120 0
2008-01-07 00:00:00.000 03 0 0 180
2008-01-07 00:00:00.000 03 0 180 0
2008-01-07 00:00:00.000 03 60 0 0
As can be seen I need the results to be in one row for each date, machine
I know I'm missing something... but cannot recall what...
Thank you in advance!Change the query to take the SUM out of the CASE function:
SELECT [Date], MachNo,
SUM(CASE WHEN Shift = 'A' THEN Quantity ELSE 0 END) AS
ShiftAQty,
SUM(CASE WHEN Shift = 'B' THEN Quantity ELSE 0 END) AS
ShiftBQty,
SUM(CASE WHEN Shift = 'C' THEN Quantity ELSE 0 END) AS ShiftCQty
FROM Prod_Knitting_Data_1
GROUP BY [Date], MachNo
HTH,
Plamen Ratchev
E-Mail: Plamen@.Ratchev.com|||select [Date], MachNo,
sum(case when Shift = 'A' then Quantity else 0 end) as
ShiftAQty,
sum(case when Shift = 'B' then Quantity else 0 end) as
ShiftBQty,
sum(case when Shift = 'C' then Quantity else 0 end) as
ShiftCQty,
from Prod_Knitting_Data_1
group by [Date], MachNo
"PsyberFox" <PsyberFox@.discussions.microsoft.com> wrote in message
news:21D07D5F-6113-403F-8E6D-FBB4F433DEFB@.microsoft.com...
> Hi there,
> I haven't used queries to put data in columns in quite some time, so I'm
> slightly rusty... I would appreciate some help with the following please:
> (SQL 2000)
> Query:
> select [Date], MachNo,
> case when Shift = 'A' then sum(Quantity) else 0 end as
> ShiftAQty,
> case when Shift = 'B' then sum(Quantity) else 0 end as
> ShiftBQty,
> case when Shift = 'C' then sum(Quantity) else 0 end as
> ShiftCQty
> from Prod_Knitting_Data_1
> group by [Date], MachNo, Shift
>
> Result (extract):
> Date Mc A B C
> 2008-01-07 00:00:00.000 01 0 0 400
> 2008-01-07 00:00:00.000 01 0 200 0
> 2008-01-07 00:00:00.000 02 0 0 0
> 2008-01-07 00:00:00.000 02 0 120 0
> 2008-01-07 00:00:00.000 03 0 0 180
> 2008-01-07 00:00:00.000 03 0 180 0
> 2008-01-07 00:00:00.000 03 60 0 0
>
> As can be seen I need the results to be in one row for each date, machine
> I know I'm missing something... but cannot recall what...
> Thank you in advance!