显示标签为“analyzer”的博文。显示所有博文
显示标签为“analyzer”的博文。显示所有博文

2012年3月19日星期一

Any way around this error

I get the error (in red) below when I run this stored procedure (I'm not running in my app but in Query Analyzer) -- Please help me fix this

CREATE PROCEDURE dbo.sp_Employee_GetEmployeeLNameFNameEmpID
(
@.facilityID nvarchar(2),
@.companyID nvarchar(2),
@.deptID nvarchar(20),
@.Period int
)
AS
SELECT e.LastName + ',' + e.FirstName + ' - ' + e.EmployeeID AS ListBoxText, e.EmployeeID, e.LastName + ',' + e.FirstName AS FullName FROM Employee e
WHERE e.DeptID = @.deptID AND e.FacilityID = @.facilityID AND e.CompanyID = @.companyID AND e.EmployeeID <> (SELECT ev.EmployeeID FROM EmployeeEval ev
WHERE PeriodID= @.Period)
GO

Server: Msg 512, Level 16, State 1, Procedure sp_Employee_GetEmployeeLNameFNameEmpID, Line 9
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

WHICH employee do you want from the ev table?
It looks to me like you want a NOT IN instead:
SELECT
e.LastName + ','+ e.FirstName + ' - ' + e.EmployeeID AS ListBoxText,
e.EmployeeID,
e.LastName + ',' + e.FirstName AS FullName
FROM Employee e
WHEREe.DeptID = @.deptID
AND e.FacilityID = @.facilityID
AND e.CompanyID =@.companyID
AND e.EmployeeID NOT IN
(SELECT ev.EmployeeID
FROMEmployeeEval ev
WHERE PeriodID= @.Period)
|||

Sweet worked perfectly -- my book showed the IN part but I didn't know about the NOT IN.
Thanks a million.

2012年3月11日星期日

Any SQL wizard can help? Reformat the input file and transfer into SQL server

I am trying to transfer 200 txt files into SQL server by using query analyzer.
The command is 'Bulk insert [tableName] from 'path\filename.txt'
However, I need to read and modifiy the txt file.
I am new to SQL server but I believe there must be some one who is a wizard can do what I want easily.

Thank you for the help in advance!

Here is the raw data layout, which is comma delimited.
BDate 1/1/1990 BDate 1/1/1990 BDate 1/1/1990 BDate 1/1/1990
Edate 1/1/2005 Edate 1/1/2005 Edate 1/1/2005 Edate 1/1/2005
Fq D Fq D Fq D Fq D
Date R P M E D Date R P M E D Date R P M E D Date R P M E D
1/1/90 1 2 3 4 5 1/1/90 2 3 4 5 6 1/1/90 3 4 5 6 7 1/1/90 4 5 6 7 8
2 3 4 5 6 1 2 3 4 5 3 4 5 6 7 6 7 8 9 1
1/1/05 ..... 1/1/05 ... 1/1/05 .... 1/1/05 ....

This is the desired output after load into the table, which is tacking each repeating block on top of each other.
Date R P M E D
1/1/90 1 2 3 4 5
2 3 4 5 6
1/1/05 .....
1/1/90 2 3 4 5 6
2 3 4 5 6
1/1/05 .....
1/1/90 3 4 5 6 7
3 4 5 6 7
1/1/05 .....
1/1/90 4 5 6 7 8
6 7 8 9 1
1/1/05 ....."I am trying to transfer 200 txt files into SQL server by using query analyzer."
--DTS might be more appropriate.

"I am new to SQL server but I believe there must be some one who is a wizard can do what I want easily."
--Faith is a powerful thing.

"Here is the raw data layout, which is comma delimited."
--What you posted is not comma delimited.

"This is the desired output after load into the table, which is tacking each repeating block on top of each other."
--You are going to need to load this data into a staging table and normalize it before loading into your production tables. The process will be complex, involving several passes through the data.

If at all possible, try to get your source data in a better format. Practically any other format would be preferable to what you posted.|||Blindman,
Thank you for your reply.
You are right... I forgot to put "," in my sample file layout.
I am using another source provider to request time series in excel. This is the most efficient way I can utilize excel ability (256 columns and over 65,000 rows). That's why the raw data layout looks wired. However, I have to stick to it.

I was thinking to load these files into a table to normalize but I am not sure if I know SQL well enough to say this is the best solution. I think I got the answer from you.

What is staging db. I assume it is one of defualt DB in in enterprise manager, however, I did not see it. Or this is the name you gave?

Thank you again for the help.
Shiparsons|||Not "Staging DB". "Staging TABLE."

A staging table is basically an table that has the same structure as your input data, with additional columns added as needed to keep track of records as they are being processed. I always add an "Imported" column that defaults to getdate(), and an ImportErrors column that I populate as necessary during processing.

Your staging table should have no Primary Keys or constraints (unless you add a surrogate PKey for processing...), so that your import process never fails because the data does not match what is expected.

Once the data is in the staging table you cleans it and make sure it satisfies all the business rules required by your production tables. Then you make as many passes through the staging table as necessary to update the various production tables it feeds, starting with the top-level tables.|||Thank you for the explanation.
What datatype I should use when I create my staging table? I assume this is nonconstraints type since my raw data contains text, datetime, and float.

Thank you,
Qing|||You should try to match the datatype to the type of the data being entered, though some people just make all staging table columns varchar by default. I don't do this, as a rule, but you may have no other choice since your import file is actually a mix of different layouts. String fields are the only column types that will accept any input type.|||Blindman,
Thank you for the help.

I will try.

shiparsons

2012年2月23日星期四

Any idea on this!

How can execute sqlscript stored in a folder.
i.e D:\SQLSCRIPT\cs_posting_exc.PRC
What can I write in query analyzer so that I can run that procedure in that
folder is a specified server and database.Have you looked into using osql.exe with xp_cmdshell? See SQL Server Books
Online for more details & post back if you have questions.
Anith

2012年2月16日星期四

any free tools for query analyzer for Sql Server 2000?

Dear all,
is there any free tools for query analyzer for SQL Server 2000?
Thank you.
Regards,
Angus
Hi Angus,
I understand that you want to know, if you can have any free tools for
Query Analyzer for SQL Server 2000.
You can try the Web Data Administrator available at
http://www.microsoft.com/downloads/d...798-C57A-419E-
ACBC-2A332CB7F959&displaylang=en
HTH
Ashish
This posting is provided "AS IS" with no warranties, and confers no rights.

2012年2月13日星期一

Any command list the tables in the Databsae

Please help. In my Enterprise Manager, there is some local database, some
other (is in another network)
IN SQL Analyzer , what command I can list out the tablelist for each
database'
ThanksSee:
http://groups-beta.google.com/group...1d?dmode=source
Anith|||check for stored procedure sp_tables in BOL
or u can make use of sysobjects table available in Master Database
best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
---
*** Sent via Developersdex http://www.examnotes.net ***|||You can use an undocumented sp (not recommended in production dbs) or declar
e
a cursor to traverse databases and execute stored procedure sp_tables in eac
h
db context.
use northwind
go
exec sp_msforeachdb 'select ''?''; use [?]; exec sp_tables @.table_type =
'''table''
go
declare @.sql nvarchar(4000)
declare @.db sysname
declare dbs_cursor cursor local fast_forward
for
select
catalog_name
from
information_schema.schemata
open dbs_cursor
while 1 = 1
begin
fetch next from dbs_cursor into @.db
if @.@.error != 0 or @.@.fetch_status != 0 break
select @.db
set @.sql = N'use ' + quotename(@.db) + N' exec sp_tables @.table_type =
'''table''
print @.sql
exec sp_executesql @.sql
end
close dbs_cursor
deallocate dbs_cursor
go
AMB
"Agnes" wrote:

> Please help. In my Enterprise Manager, there is some local database, some
> other (is in another network)
> IN SQL Analyzer , what command I can list out the tablelist for each
> database'
> Thanks
>
>

Any 3rd party tools for integrating VSS w/ query analyzer or similar?

Are there any 3rd party tools that allow VSS to be directly intergrated with
Query Analyzer? Or are there replacements for Query Analyzer that have VSS
built in?
We found http://www.mssqlXpress.com , but it likely has more bells and
whistles than we need and/or want to pay for. We just need/want QA with VSS
built in ...
Thanks in advance!
MarkOne thing you can do is add VSS to the external tools in Query analyzer
passing command line parameters...
SS.exe I think is VSS executable...For instance to check out the current
file..
Command: ss.exe
Arguments; checkout $(Filename)$(FileExt) -C-
Initial Directory: $(FileDir)
Ken Henderson covers some of this in his new book 'The Guru's Guide to SQL
Server Architecture and Internals'...
It's a good book , I recommend it.!
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Mark" <mfield@.idonotlikespam.cce.umn.edu> wrote in message
news:eaeFIaxlDHA.2272@.tk2msftngp13.phx.gbl...
> Are there any 3rd party tools that allow VSS to be directly intergrated
with
> Query Analyzer? Or are there replacements for Query Analyzer that have
VSS
> built in?
> We found http://www.mssqlXpress.com , but it likely has more bells and
> whistles than we need and/or want to pay for. We just need/want QA with
VSS
> built in ...
> Thanks in advance!
> Mark
>