|
-
Apostrophes in parsed data.
Date: 06/15/05
Keywords: sql
Okay, so I'm pulling a text file into SQL Server 2000 using an ActiveX script. Script works flawlessly on a number of other files. It shunts records to various tables depending on markers in the data itself, splitting the data, assigning record numbers, and then using an INSERT INTO statement to actually get the data into the tables. A typical (short) INSERT INTO statement looks like this:
DestSQL = "INSERT INTO amt VALUES (" & recordnum & "," & subrecordnum & ",'" & _ sArray(0) & "','" & sArray(1) & "','" & sArray(2) & "','" & sArray(3) & "')"
The data from the text file is all character data (and it really IS character data, i.e., I can't convert it all into numerics or what have you), thus the need for the single quotes.
...and now, the dilemma. A new client just sent me a test file to run through to make sure we can process it. It bombed. I dug through the data for half an hour or so trying to figure out why before realizing that the data contains... apostrophes! And thus, the INSERT INTO statement comes out looking like...
INSERT INTO n3 VALUES (1,23,'MONTAN'S BAY','OH','44121','')"
You can see the problem immediately. (Which is better than I can say for me. sheesh.)
Here's the monkeywrench: while I was only tasked with this this morning, we'll start getting regular cuts from the client in July. No idea when in July yet, so I'm figuring a worst-case scenario of July 5.
Here's the spanner attached to the monkeywrench: for various reasons, I have various vacation days planned between now and July 5 that I can't get out of. I have eight and a half days to have this up and running. Along with all the other stuff I gotta do. So rewriting the package from scratch is probably out.
I'm thinking of going through each line and stripping out the apostrophes, but I'm sure everyone involved would rather have the data look the same way coming out of the package that it went into the package (except stuffed into tables).
Anyone know of a quick and dirty way to get apostrophes past an INSERT INTO statement? Thanks...
Source: http://www.livejournal.com/community/sqlserver/28770.html
-
SQL 2K5 Express Manager
Date: 06/14/05
Keywords: software, technology, database, sql
I have a standalone system (WinXPPro) which has MSDE. This system will never have full-blown SQL Server, and will probably never have SQL Server 2005 Express edition (at least not until the other software running on it is certified for SQL2k5 Express)
I'm interested in having some simple tool to serve the same role as Enterprise Manager and Query Analyser do in SQL2k (queries, backups, database mods, etc). I'm thinking of downloading the SQL Server 2005 Express Manager, and using it for some simple database management tasks.
Has anyone downloaded the April CTP (Community Technology Preview) version of this tool? If so, how do you like it? Does it work well with MSDE? If I want to avoid mixing versions and avoid using unreleased and unsupported tools, is there an equivalent tool for MSDE 2000?
Source: http://www.livejournal.com/community/sqlserver/28608.html
-
Considering moving to ASP.Net 2005 Beta 2?
Date: 06/12/05
Keywords: html, asp
Anyone considering moving to ASP.Net 2005 Beta 2 may want to read this: http://www.damn-them.com/it/2005/06/transition-to-aspnet-2005-beta-2.html
(Cross Posted)
Source: http://www.livejournal.com/community/sqlserver/28171.html
-
Invalid Arguement
Date: 06/06/05
Keywords: sql
Hi Gang -
trying to run a make-table query. Can someone look at the SQL and tell me why access keeps returning an "Invalid Arguement" error. Thanks in advance
SELECT BI.NRS_STATION, BI.BED_ABBREV, PHM_ORDERS.ADDL_SIG_1, PHM_ORDERS.ADDL_SIG_2, PHM_ORDERS.ADDL_SIG_3, PHM_ORDERS.ADDL_SIG_4, BI.PTNAME, BI.PAT_NUM, BI.PTSEX, BI.PTAGE, BI.PTMEDREC, BI.ITN, BI.PTCLASS, BI.ATTDOCNU, BI.ATTDOCNA, BI.SITE, PHM_ORDERS.PMP, PHM_ORDERS.MED_IV, PHM_ORDERS.COMPONENT_TYPE, PHM_ORDERS.DOSE, PHM_ORDERS.START_DATE, PHM_ORDERS.STOP_DATE, PHM_ORDERS.STOP_TIME, PHM_ORDERS.LATIN_DIR_ABBR, PHM_ORDERS.FREQUENCY, PHM_ORDERS.ROUTE, PHM_ORDERS.DR_NO, PHM_ORDERS.DR_NAME, PHM_ORDERS.GENERIC_NAME, PHM_ORDERS.DOSAGE_FORM, PHM_ORDERS.DRUG_CODE, PHM_ORDERS.SOL_VOLUME, PHM_ORDERS.RATE, PHM_ORDERS.RUN_IN_TIME, PHM_ORDERS.VALIDATED_BY, PHM_ORDERS.IV_METHOD, PHM_ORDERS.CANCELLED, PHM_ORDERS.SUSPEND_DATE, PHM_ORDERS.SUSPEND_TIME, PHM_ORDERS.RESUME_DATE, PHM_ORDERS.RESUME_TIME, PHM_ORDERS.STRENGTH, PHM_ORDERS.ACTIVE_COMPONENT, PHM_ORDERS.ACTIVE_UB, PHM_ORDERS.SUSPENDED, PHM_ORDERS.STOPPED INTO mart FROM BI INNER JOIN PHM_ORDERS ON BI.ITN = PHM_ORDERS.ITN WHERE (((BI.PAT_NUM)=[Forms]![frm_mar]![ctlptno]) AND ((BI.ITN)>"0") AND ((PHM_ORDERS.VALIDATED_BY)<>"") AND ((PHM_ORDERS.ACTIVE_COMPONENT)="YES") AND ((PHM_ORDERS.ACTIVE_UB)<>"NO") AND ((PHM_ORDERS.SUSPENDED)="NO") AND ((PHM_ORDERS.STOPPED)="NO"));
Source: http://www.livejournal.com/community/sqlserver/27880.html
-
Hey..
Date: 06/03/05
Keywords: cms, database, sql, web, seo, microsoft
Hey everybody. I hope there are some smart database people out there to make up for my lack of knowledge.
Anyway, I have a (hopefully) rather simple question.
I work at the local university maintaining the webpage for the nursing program here. The ladys I work for are not very computer smart, so I'm trying to develop an easier way for them to upload new data to class pages, new homework assignments, new lecture slides, etc etc etc. Basically a kind of micro-cms system.
Yes, I'm reinventing the wheel, but I feel it will be a good experience for me.
Well, I'm using .NET for this (C#) because of what's available here at school, and while in the end, everything will be on the SQL Server, for development purposes the webmaster for the school has said that I need to use MS Access.
Blech. Hopefully I won't have to change a whole lot of stuff for the migration to happen, but for now I'm stuck.
Unfortunately, while I can figure out the Queries and the basic commands, actually connecting to a MS Access database is proving to be rather difficult for me. I cannot seem to find an authoratative guide on what all I need to put to create the connect.
Most of the functions are going to be located in a seperate file, and once its all compiled, it should (hopefully) work. But I cannot seem to find what the connect string is.
In my databaseConnect() function I have this:
void databaseConnect() { String connectionString = "Provider=Microsoft.Jet.Oledb.4.0;"; connectionString += "Data Source=I:/web/nursing/dev/resources/exams/nursingExams.mdb;"; createUpdateExamConnection = new OleDbConnection (connectionString); databaseOpen(); } //end databaseConnect
For some reason, this just doesn't seem to work.
I've imported the correct thing, as far as I can tell...
using System.Data.OleDb;
But I'm stuck.
Any info that you guys can give me would be appreciated.
Thanks so much!
Source: http://www.livejournal.com/community/sqlserver/27485.html
-
LEFT function ntext data type
Date: 05/20/05
Keywords: sql
Hello everyone,
I know that you cannot do the following if columnName is ntext datatype:
SELECT LEFT(columnName, 400)
Is there another way to achieve the same effect in the SQL query itself?
Source: http://www.livejournal.com/community/sqlserver/27272.html
-
MySQL -> MS SQL SQL Create Script
Date: 05/19/05
Keywords: mysql, sql, web
Hello everyone,
We've got a MySQL DB on a solaris box that is going to be retired shortly and we need to move the data source for a web application from MySQL to MS SQL. I dont't work with MySQL as much, so I would like to know if anyone can tell me how to get a SQL create script out of the MySQL db so that I can recreate it in MS SQL.
peace.
Source: http://www.livejournal.com/community/sqlserver/26975.html
-
VBScript again...
Date: 05/17/05
Keywords: no keywords
Gah, I hope this is my last question on this bit...
(quick refresher: this is an ActiveX script in a DTS package.)
Okay, I'm getting errors with the following seemingly very simple lines of code: dim recordnum set recordnum = 0 This gives me the following error: object required: '[number: 0]'
Tried changing it to: dim recordnum set CInt(recordnum) = 0 and got a type mismatch error.
So I went with the absurd: dim recordnum set recordnum = CInt(0) and got object required: 'CInt(...)'
very confused. Only thing I've been able to find on the net is that Windows Script Host is not installed; my network guy swears it is.
Anyone know anything else it might be? Thanks.
Source: http://www.livejournal.com/community/sqlserver/26696.html
-
another exceptionally dumb question...
Date: 05/11/05
Keywords: database, sql
...on the same VBScript thing I'm trying to come up with in DTS. I'm sure this is another "it's very obvious, you just haven't put the piece together correctly" kind of question.
Okay, to recap fast: I'm importing a text file and shunting each record off into one of a series of possible places for some quick processing (I'm keeping the test cases in the SELECT CASE statement to the simplest possible options, so I can make sure I have a running skeleton before getting into any more complex processing)-- right now, it's simply splitting the line and copying it into a table (REF or ISA, depending). Then I realized...
[snip a bunch of stuff]
dim MyDestConnREF
set MyDestConnREF = CreateObject("ADODB.Connection")
MyDestConnREF.Open = "Provider=SQLOLEDB.1;Data Source=TESLA;Initial Catalog=EDI;userid=sa'password=nothing"
dim MyDestConnISA
set MyDestConnISA = CreateObject("ADODB.Connection")
MyDestConnISA.Open = "Provider=SQLOLEDB.1;Data Source=TESLA;Initial Catalog=EDI;userid=sa'password=nothing"
[snip a bunch of stuff]
select case ucase(trim(left(dtssource("Col001"),3)))
case "REF"
redim sArray(4)
DTSDestination("recordnum") = recordnum
DTSDestination("subrecordnum") = subrecordnum
DTSDestination("type") = sArray(0)
DTSDestination("refnumqual") = sArray(1)
DTSDestimation("refnum") = sArray(2)
DTSDestination("description") = sArray(3)
DTSDestimation("refid") = sArray(4)
case "ISA"
redim sArray(16)
[snip a bunch of stuff]
How to I tell it that the columns in DTSDestination in this excerpt pertain to the REF table, as opposed to ISA (or any other table in the database)? I can't seem to find a parameter in Connection.Open that will let me specify a table, and since I'm working with multiple tables, I'm not going to have a default destination-- I'm going to have multiple destinations in the same script.
Thanks.
Source: http://www.livejournal.com/community/sqlserver/26495.html
-
VBScript in DTS...
Date: 05/09/05
Keywords: sql
...in SQL Server 2000.
I'm not sure what I want to do can actually be done, and my leafing through VBScript books/searching on the Internet has not brought me any closer to figuring it out. Hoping someone here may have an answer. (If there's a non-scripting solution, I'd certainly be open to that-- in fact, I'd prefer it.)
I'm reading in a text file. Each line of the file must go into one of a number of different tables based on certain criteria contained within the line itself. What I'm wondering is if there's a way to structure the data pump (or a different type of task) to read the line, look for the necessary criterion, and then shunt the line off into a table.
The way I'm doing it now has the text file going into a staging table, then parsing it from there. It seems to me that parsing the text file as it comes in would make for a pretty serious speed increase. As the package I have in place now takes approx. seven hours to run (and over half of that importing/parsing/getting stuff to tables), any increase in speed would be very welcome...
thanks.
Source: http://www.livejournal.com/community/sqlserver/26295.html
-
String or binary data would be truncated.
Date: 04/20/05
Keywords: no keywords
Here's a select statement.
insert into eligstaging2(recordnum, emembno, elstnam, efstnam, eadrln1, eadrln2, ecitycd, estacod, ezipcod, ebthdat, esexcod, eeffdat, ecommcd, etiercd, egrpnum, eexpdat, erecordnum, drecordnum) select employees.recordnum, left(employees.emembno,11), left(employees.elstnam,15), left(employees.efstnam,15), left(employees.eadrln1,25), left(employees.eadrln2,25), left(employees.ecitycd,15), left(employees.estacod,2), left(employees.ezipcod,10), left(employees.ebthdat,8), left(employees.esexcod,1), left(employees.eeffdat,8), left(employees.ecommcd,2), left(employees.etiercd,3), left(employees.egrpnum,16), left(employees.eexpdat,8), eligstaging.erecordnum, eligstaging.drecordnum from employees inner join eligstaging on employees.recordnum = eligstaging.erecordnum
employees and eligstaging2 are identical tables, except that eligstaging2 contains two extra fields at the end, erecordnum and drecordnum. Both are int fields both in eligstaging (the source table for these columns) and eligstaging2. In order to make absolutely sure that there's no possibility for truncation I don't know about, as you can see, I've enclosed every character field in the query in left() statements with the length of the column as the length argument.The only non-character column in employees is recordnum, which is also an int. The column lengths are correct; I've checked both takes five times, both against each other and against the query. I am 100% sure that those numbers are correct. Also, I'm not inserting new numbers into the int columns, I'm inserting numbers that are coming from other int columns, so there can't be any numbers that don't fit into int columns. (Actually, the largest number in the test file I'm using is 59, so that's defniitely not the problem.)
Can someone tell me where else string or binary data might be truncated and what to do about it, because I swear I've covered every base, and I'm still getting the error. Thanks.
Source: http://www.livejournal.com/community/sqlserver/24835.html
-
SELECT statement woes.
Date: 04/18/05
Keywords: no keywords
Okay, I'm at a logjam on this, and I desperately need to get it fixed. My present code is definitely not working-- it's pulling way, way too many records, and I need an answer fast. If any of you happen to have one, I'd greatly appreciate it.
You have three types of tables.
Type 1: the Employees table. It contains a recordnum field, and a number of other, irrelevant for the purposes of the question, fields. Type 2: the Link table. It contains two columns, erecordnum and drecordnum. "E" stands for emplyees, "D" for dependents. Type 3: one or more (in my case, six at the moment, eventually twenty-nine) tables, all of which have recordnum fields.
Recordnum is an arbitrary number that goes from one to (in this case) 667,770. The Employees table contains the actual employee records-- for example, my first eight employee records are 2, 4, 5, 7, 8, 12, 14, and 15. Dependents are listed sequentially under the employees, so for employee 2, dependent would be 3. For employee 8, dependents would be 9, 10, and 11. Thus, the link table looks like this for the first bunch of records:
erecordnum drecordnum 2 2 2 3 4 4 5 5 5 6 7 7 8 8 8 9 8 10 8 11 12 12 12 13 14 14 15 15 ...etc. (That the employees are showing up as dependents in the link table is intentional for various reasons.)
What I need is a SELECT statement that will pull all the relevant information I need form these tables. The Employees table already has everything I need for the employee records, but I need to add columns for each dependent, so the final table will look like the Link table above (i.e., all the employee information will be repeated for each dependent). The problem I'm having is in figuring out how to write the WHERE clause so that it's pulling the right rows, and only the right rows, from each table. My present SELECT statement:
insert into elig (emembno, efstnam, elstnam, eadrln1, eadrln2, ecitycd, estacod, ezipcod, ebthdat, esexcod, egrpnum, eeffdat, eexpdat, ecommcd, etiercd, drelcod, dmembno, dfstnam, dlstnam, dbthdat, dsexcod, deffdat, dexpdat, ehomppg, ecntycd, action, termdate, ephoneno, filler) select e.emembno, e.efstnam, e.elstnam, e.eadrln1, e.eadrln2, e.ecitycd, e.estacod, e.ezipcod, e.ebthdat, e.esexcod, e.egrpnum, e.eeffdat, e.eexpdat, e.ecommcd, e.etiercd, ins.relcode, nm1.idcode, nm1.fstnam, nm1.lstnam, dmg.dtperiod, dmg.sex, d1.dtperiod, d2.dtperiod, space(3), space(2), hd.mainttype, space(8), space(10), space(10) from employees e inner join eligstaging e1 on e.recordnum = e1.erecordnum left join ins on e.recordnum = e1.erecordnum and ins.recordnum = e1.drecordnum left join nm1 on e.recordnum = e1.erecordnum and nm1.recordnum = e1.drecordnum left join dmg on e.recordnum = e1.erecordnum and dmg.recordnum = e1.drecordnum left join dtp d1 on e.recordnum = e1.erecordnum and d1.recordnum = e1.drecordnum and d1.dtqual = '348' left join dtp d2 on e.recordnum = e1.erecordnum and d2.recordnum = e1.drecordnum and d2.dtqual = '349' left join hd on e.recordnum = e1.erecordnum and hd.recordnum = e1.drecordnum where e.egrpnum <> 'DO NOT LOAD'
This is obviously not working, because instead of getting the 671K records I'm expecting, I'm getting enough records to fill about 100GB worth of temp space, maxing out the system and causing the query to abort. Can someone point out to me what changes I need to make in this statement to pull just the records I need?
Thanks.
Source: http://www.livejournal.com/community/sqlserver/24798.html
-
Reading XML and using in a SELECTstatement
Date: 04/15/05
Keywords: xml, sql
I have an XML document which contains 10,000 rows of item master information, 12 columns per row. I want to read that XML document and use it in a SELECT statement, just as if it was a table or view.
The SQL help file suggests using OPENXML, which looks pretty simple, but in order to use that, I need to create an internal representation of the XML document with sp_xml_preparedocument. In order to do THAT, I have to have the entire XML document in a text parameter. This is not a small file (4.8MB), and is representing about 10,000 rows of data. No way in hell can I pull all of that into an ntext variable.
I have never worked with XML in SQL Server before. I am familiar with the data in the document (.XML file contains the schema information in the header) but not with the T-SQL functions and procedues used to manipulate XML data.
How do I read the XML file, either as a part of a SQL SELECT, or by dumping it into a temporary cursor?
Source: http://www.livejournal.com/community/sqlserver/24405.html
-
Transact SQL Training
Date: 04/06/05
Keywords: sql
My boss asked me to do some research to find Transact SQL training for people at work which wouldn't be too expensive. Everyone (I hope) has basic skills with using Select statements and such. We mostly do a lot of report writing, but the need is for everyone to have more understanding and be able to manipulate data and be able to pull in data from other sources (Conversions from competitor systems to ours) and also be able to write procedures, functions and triggers.
Any suggestions which wouldn't break the bank? Local colleges have prerequisites that I don't think most here would have already. Also the two main colleges teach using Oracle and Sybase, while we only use MS SQL now, but will most likely branch off in the future.
Thanks for any input provided.
Xposted to DB_Community
Source: http://www.livejournal.com/community/sqlserver/23315.html
-
fileslistonly vs. verifyonly restores
Date: 03/31/05
Keywords: no keywords
Hey all. I have a quick question I was wondering if anyone had any experience with. Does anyone know if a successful completion of a 'restore filelistonly' command would indicate that a backup file is valid? I've noticed some of our backup jobs failing during the verify phase of the maintenenace plan because of network issues, and I'd like a quick way to check if the backup is valid because some of the backup files take hours to verify.
Source: http://www.livejournal.com/community/sqlserver/23255.html
-
100% cpu usage
Date: 03/30/05
Keywords: sql, web
My sql server is driving me crazy. It's pegging out at 100% CPU for almost anything. dropping tables, truncating tables. It will be at 0% CPU, I'll attempt to drop a table and it will sit at 100% until I cancel the request. Some of my webpages are timing out. Anyone have any idea where to start? Event viewer doesnt give much info.
I'm running sql server 2000 sp3 on win2k3 sp1.
Source: http://www.livejournal.com/community/sqlserver/22992.html
-
Noob.
Date: 03/25/05
Keywords: mysql, database, sql
I'm used to working with MySQL and I have to make this forray into SQL server. So, I need a quick bit of help.
I need to be able to browse through a database one record at a time. For that, I guess I need a way to give my query a start row and. I can end it just fine. What should I use? And how do I figure out what row I am currently on. With MySQL theres the LIMIT clause and I know thats not available in SQL server.
Thanks in advance.
Source: http://www.livejournal.com/community/sqlserver/22596.html
-
Access to SQL Server Question
Date: 03/24/05
Keywords: database, sql
Using ONLY T-SQL (a stored proc really), is there a way to gain access to a MS Access DB and pull data out of it into a SQL Server database?
I know one theoretical solution is to create a linked server against the MS Access DB, pull my data out that way, kill the linked server property, and go along my merry way, but there's gotta be a better way to do this!
And no, DTS really isn't an option either I'm afraid.
x-posted to databases
Source: http://www.livejournal.com/community/sqlserver/22438.html
-
Proper Case formula
Date: 03/18/05
Keywords: no keywords
Hello …. I’m new here. Apologies if this is inappropriate, but I am sufficiently frustrated so I thought I would ask a collective intelligence. I'm working on a formula I have in a Crystal report. Actually, it’s a formula I found online, and it
*almost* suits my needs. Let me add that I’m working with CR 8.5 (and need to in order for it to remain compatible with another system at my work), so I cannot utilize the Proper Case function introduced in CR 9. I’ve also tried downloading the UFL for Title Case, and that turned out to be more trouble than help. So I’m back to trying to perfect the formula. The formula looks like this: ⁄⁄CONVERT FIELD TO PROPER CASE
Local Numbervar x; Local Numbervar i; Local Stringvar Holder; Local Stringvar Final; Local Stringvar Proper; Local Stringvar vString;
vString := trim({DBfield}); x := length(vString);
If x >= 1 then ( For i := 1 to x do ( Select vString[i] Case " ": ( (If Final in ["P.O.", "U.S.", "C⁄O", "PO"] then (Final := Uppercase(Final); Proper := Proper + Final + " "; Holder := ""; Final := "") Else Holder := Uppercase(Final)[1]; Final := Final[2 to (i-1)]; Proper := Proper + Holder + Final + " "); Holder := ""; Final := "" )
Default:
( Holder := Holder + Lowercase(vString)[i]; Final := Final + Holder; Holder := "" );
);
Holder := Uppercase(Final)[1]; Final := Final[2 to (i-1)]; Proper := Proper + Holder + Final; Holder := ""; Final := ""; x := 0; i := 0; Proper ) Else "" This successfully takes a name that is formatted like so: BLOW,JOE and turns it into this: Blow,joe What I need it to do is take the comma into consideration, add a space after the comma, and capitalize the first name as well, like so: Blow, Joe If there's a middle initial, it's be great if there was a period after it, but I'm not that concerned about that at the moment.
Any chance someone knows how to fix this?
Source: http://www.livejournal.com/community/sqlserver/21891.html
-
A query..
Date: 03/14/05
Keywords: database, asp
A procedure I wrote that doesn't work..
create proc cal(@days as int, @num as real output) as BEGIN DECLARE @h int, @l int, @r int, @a int, @b int, @c int, @blah real set @h=(select sum(heritage) from loctab); set @l=(select sum(leisure) from loctab); set @r=(select sum(religion) from loctab); set @a=(select heritage from loctab where locid='vzg'); set @b=(select leisure from loctab where locid='vzg'); set @c=(select religion from loctab where locid='vzg');
set @blah=((@a+@b+@c)/(@h+@l+@r))*@days; set @num=@blah return @num END
***
The value of @num should be between 2 and 3 but its returning a zero to my ASP.NET page. I think something's wrong with the division operation there. Any idea what I should do to make it work??
Also, can I convert this into a cursor to make it work for all locid's in the database?
Thanks.
Source: http://www.livejournal.com/community/sqlserver/21566.html
|