Showing posts with label program. Show all posts
Showing posts with label program. Show all posts

Thursday, March 29, 2012

data table foriegn key problem

I am just learning how to program in SQL, so please be patient with me

ok, here it is, i am getting the following errors with my script when i try to execute, and although i realize that this is not the best style to write my script in, i am trying to learn why this is erroring. the errors are:

Msg 1769, Level 16, State 1, Line 9

Foreign key 'Employee2Job_Title' references invalid column 'Title' in referencing table 'Employee'.

Msg 1750, Level 16, State 0, Line 9

Could not create constraint. See previous errors.

now i realize that the second error is because of the first, and that if i can fix the first, the second will go away. Thanks for the help.

Here is my script

use inventory

go

CREATE TABLE Job_Title

(Job_Title_Title char(25) NOT NULL ,

Job_Title_EEO1_Classification char(25) ,

Job_Title_Job_Description Varchar(45) ,

Job_Title_Exempt_Status Varchar(15)

, PRIMARY KEY (Job_Title_Title)

);

CREATE TABLE Employee

(Employee_Emp_ID integer NOT NULL ,

Employee_last_name varchar(15) ,

Employee_first_name varchar(15) ,

Employee_address varchar(30) ,

Employee_city varchar(15) ,

Employee_state char(2) ,

Employee_Telephone_area_code char(3) ,

Employee_Telephone_number char(8) ,

Employee_EEO1_Classification char(25) ,

Employee_Hire_Date char(8) ,

Employee_Salary char(6) ,

Employee_Gender Varchar(1) ,

Employee_Age char(2) ,

Employee_Title char(25)

, PRIMARY KEY (Employee_Emp_ID)

, constraint Employee2Job_Title FOREIGN KEY (Title

) REFERENCES Job_Title

);

Insert INTO Employee (Emp_ID, Last_name, First_name, Address, City, State, Telephone_area_code, Telephone_number, EEO1_Classification, Hire_date, Salary, Gender, Age, Title) Values

(1, 'Edelman', 'Glenn', '175 Bishop Lane', 'La Jolla', 'CA', 619, '555-0199', 'Sales Workers', 10/7/2003, 21500.00, 'M', 64, 'Cashier')

Insert INTO Employee (Emp_ID, Last_name, First_name, Address, City, State, Telephone_area_code, Telephone_number, EEO1_Classification, Hire_date, Salary, Gender, Age, Title) Values

(2, 'McMullen', 'Eric', '762 Church Street', 'Lemon Grove', 'CA', 619, '555-0133', 'Sales Workers', 11/1/2002, 13500.00, 'M', 20, 'Bagger')

Insert INTO Employee (Emp_ID, Last_name, First_name, Address, City, State, Telephone_area_code, Telephone_number, EEO1_Classification, Hire_date, Salary, Gender, Age, Title) Values

(3, 'Slenj', 'Raj', '123 Torrey Drive', 'North Clairmont', 'CA', 619, '555-0123', 'Officials & Managers', 6/1/2000, 48000.00, 'M', 34, 'Assistant Manager')

Insert INTO Employee (Emp_ID, Last_name, First_name, Address, City, State, Telephone_area_code, Telephone_number, EEO1_Classification, Hire_date, Salary, Gender, Age, Title) Values

(4, 'Broun', 'Erin', '2045 Parkway Apt 2b', 'Encinitas', 'CA', 760, '555-0100', 'Sales Workers', 3/12/2003, 10530.00, 'F', 24, 'Bagger - 30 hours/wk')

Insert INTO Employee (Emp_ID, Last_name, First_name, Address, City, State, Telephone_area_code, Telephone_number, EEO1_Classification, Hire_date, Salary, Gender, Age, Title) Values

(5, 'Carpenter', 'Donald', '927 Second Street', 'Encinitas', 'CA', 619, '555-0154', 'Office/Clerical', 11/1/2003, 15000.00, 'M', 18, 'Stocker')

Insert INTO Employee (Emp_ID, Last_name, First_name, Address, City, State, Telephone_area_code, Telephone_number, EEO1_Classification, Hire_date, Salary, Gender, Age, Title) Values

(6, 'Esquivez', 'David', '10983 North Coast Highway Apt 902', 'Encinitas', 'CA', 760, '555-0108', 'Operatives (Semi skilled)', 7/25/2003, 18500.00, 'M',25, 'Asst. - Butchers & Seafood Specialists')

Insert INTO Employee (Emp_ID, Last_name, First_name, Address, City, State, Telephone_area_code, Telephone_number, EEO1_Classification, Hire_date, Salary, Gender, Age, Title) Values

(7, 'Sharp', 'Nancy', '10793 Montecino Road', 'Ramona', 'CA', 858, '555-0135', 'Sales Workers', 7/12/2003, 21000.00, 'F', 24, 'Cashier')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Accounting Clerk', 'Office/Clerical', 'Computes, Classifies, records, and verifies numerical data for use in maintaining accounting records.', 'Non-Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Assistant store manager', 'Officials & Mangers', 'Supervises and coordintes activities of workers in department of food store. Assist store manager in daily operations of store.', 'Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Bagger', 'Sales Worker', 'Places customer orders in bags. Performs carry out duties for customers.', 'Non-Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Cashier', 'Sales Worker', 'Operates Cash register to itemize and total customers purchases in grocercy store', 'Non-Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Computer Support Specialist', 'Technician', 'Installs, Modifies, and makes minor repairs to personal computer hardware and software systems and provides technical assistance and training to system users.', 'Non-Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Director of Finance & Accounting', 'Officials & Mangers', 'Plans and directs finance and accounting activites for Kudlser Fine Foods.', 'Non-Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Retail Asst. Bakery & Pastry', 'Craft Workers (Skilled)', 'Obtains or prepares Bakery and Pastry items requested by customers in retail food store.', 'Non-Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Retail Asst. Butchers and Seafood Specialists', 'Operatives (Semi skilled)', 'Obtains or prepares Meat and Seafood items requested by customers in retail food store.', 'Non-Exempt')

Insert into Job_Title (Title, EEO1_Classification, Job_Description, Exempt_Status) Values

('Stocker', 'Office/Clerical', 'Stores, prices, and restocks merchandise displays in store.', 'Non-Exempt')

In your foreign key that you are creating with:

constraint Employee2Job_Title FOREIGN KEY (Title) REFERENCES Job_Title

The column named Title needs to exist in the Employee table on which you are creating the constraint. Then for the column it points to with the REFERENCES part, the needs to be in the format of ReferenceTable(ReferenceTableColumnName)

If I'm guessing right at your tables, I think what you are looking for is more along the lines of

constraint Employee2Job_Title FOREIGN KEY (Employee_Title) REFERENCES Job_Title(Job_Title_Title)

-Sue

|||ok, here is the code i ended up with that cured that problem

CREATE TABLE Job_Title
(Job_Title_Title char(25) NOT NULL ,
Job_Title_EEO1_Classification char(25) ,
Job_Title_Job_Description Varchar(45) ,
Job_Title_Exempt_Status Varchar(15)
, PRIMARY KEY (Job_Title_Title)
);

CREATE TABLE Employee
(Employee_Emp_ID integer NOT NULL ,
Employee_last_name varchar(15) ,
Employee_first_name varchar(15) ,
Employee_address varchar(30) ,
Employee_city varchar(15) ,
Employee_state char(2) ,
Employee_Telephone_area_code char(3) ,
Employee_Telephone_number char(8) ,
Employee_EEO1_Classification char(25) ,
Employee_Hire_Date char(8) ,
Employee_Salary char(6) ,
Employee_Gender Varchar(1) ,
Employee_Age char(2) ,
Employee_Title char(25)
, PRIMARY KEY (Employee_Emp_ID)
, constraint Employee2Job_Title FOREIGN KEY (Employee_Title
) REFERENCES Job_Title
);

but now i am on to new and even more frustrating errors, and i will do some work on them myself, on the morrow, then if i am still having problems, i will again avail myself of this resource.

thanks much sue, your assistance has been invaluable!sql

Tuesday, March 20, 2012

data provider or other service returned an E_Fail status in sql server 2005

after converting database from sql server 2000 to sql server 2005. my program on vb6 is facing runtime error. i.e.data provider or other service returned an E_Fail status .

how can i get rid this problem

Could you please post your connection string and the exact error message that you are getting.

Jag

|||

Main_Module.STRCNNN1 = "driver={SQL Server};server=" & Main_Module.Server_Name & ";" & _
"uid=SA;pwd=;database=" & Main_Module.Common_Database
error msg is

runtime error

data provider or other service returned an E_Fail status in sql server 2005

when i am fetching record from view using order by clause in select statement then error is coming

as

select * from vew_emp where grade='C' order empno

at the first time it fetching record with order by

but when i am using recordset.Requiry

it cud not fetch the record

i think when the recordset is open with the record of view

i am deleting ,inserting record in the view base table then the main recordset is not working

without using order by it is running and working well
plz reply me quickly

Friday, February 24, 2012

data length more than ...

Hello
I have problem with reading from XML when XML is to large.
Program delare 1-n variables where is declaration but can no make more
delarations than length 8000 :((

drop table tblBooksEx
CREATE TABLE [tblBooksEx] (
[Row_ID] [int] IDENTITY (1, 1) NOT NULL ,
[BooksData] [text] COLLATE Polish_CI_AS NULL ,
CONSTRAINT [PK__tblBooksEx__17036CC0] PRIMARY KEY CLUSTERED
(
[Row_ID]
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
insert into tblBooksEx(booksdata) values('')
exec master..xp_cmdshell 'TextCopy.exe /S serv /U usr /Ppsv /D Northwind /T
tblBooksEx /C BooksData /F c:\SCN.xml /W "WHERE Row_ID=1" /I'

/*PART 1*/
DECLARE @.id int
DECLARE @.idoc int
SET @.id = 1 -- or whatever the id

DECLARE @.datalen int
DECLARE @.sql varchar(8000)
DECLARE @.sql1 varchar(8000)
DECLARE @.cnt int
-- get the length
SELECT @.datalen = DATALENGTH (booksdata) / 4000 + 1 FROM tblBooksEx WHERE
row_id = @.id

-- phase 1 collect into @.sql declarations of @.str1, @.str2,...@.strn
SET @.cnt = 1
SET @.sql='DECLARE '
SET @.sql1 = ''
WHILE (@.cnt <= @.datalen)
BEGIN
SELECT
@.sql = @.sql + CASE @.cnt
WHEN 1 THEN ''
ELSE ', ' + CHAR(13)
END
+ ' @.str'+CONVERT(varchar(10),@.cnt)+' VARCHAR(4000)'
SET @.cnt = @.cnt + 1
END
-- phase 2 collect into @.sql selection of chunks (takng care of length)
SET @.cnt = 1
WHILE (@.cnt <= @.datalen)
BEGIN
IF LEN(@.sql) < 7850
SELECT @.sql = @.sql + CHAR (13) +
'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
REPLACE(SUBSTRING(booksdata, ' +
CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
CHAR(39)+CHAR(39) ) ' +
'FROM tblBooksEx ' +
'WHERE row_id = ''' + cast(@.id as varchar) + ''''
ELSE
SELECT @.sql1 = @.sql1 + CHAR (13) +
'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
REPLACE(SUBSTRING(booksdata, ' +
CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
CHAR(39)+CHAR(39) ) ' +
'FROM tblBooksEx ' +
'WHERE row_id = ''' + cast(@.id as varchar) + ''''
SET @.cnt = @.cnt + 1
END

/*PART 2*/
-- phase 3 preparing the 2nd level dynamic sql
SELECT @.sql1 = @.sql1 + CHAR(13) + 'EXEC ('+ CHAR(13) + '''DECLARE @.idoc
int'+ CHAR(13) +
'EXEC sp_xml_preparedocument @.idoc OUT, ''' + '
SET @.cnt = 1
WHILE (@.cnt <= @.datalen)
BEGIN
SELECT @.sql1 = @.sql1 + CHAR (13) + '@.str' + CONVERT (varchar(10), @.cnt) + '
+'
SET @.cnt = @.cnt + 1
END
SET @.sql1 = @.sql1 + ' ''' '
SET @.sql1 = @.sql1 + CHAR(13) + 'DECLARE idoc_cur CURSOR FOR SELECT @.idoc'''
+CHAR(13) + ')'
--debug code
/*
PRINT @.sql
PRINT '@.sql length=' +convert(varchar(5),datalength(@.sql))
PRINT '----'
PRINT @.sql1
PRINT '@.sql1 length=' +convert(varchar(5),datalength(@.sql1))
*/
EXEC (@.sql + @.sql1)
OPEN idoc_cur
FETCH NEXT FROM idoc_cur into @.idoc
DEALLOCATE idoc_cur

select * from OpenXML(@.idoc, '//transfer/body', 2) WITH (ng int, nk int, dw
nvarchar(50))
--When Complete
--/*
exec sp_xml_removedocument @.idoc
--*/

How to solve this problem??

Best Regards
AJA
"AJA" <ajanospam74@.gazeta.plwrote in message
news:eudi64$2c3$1@.inews.gazeta.pl...

Quote:

Originally Posted by

Hello
I have problem with reading from XML when XML is to large.
Program delare 1-n variables where is declaration but can no make more
delarations than length 8000 :((


If this is SQL 2005, try varchar(max)

Quote:

Originally Posted by

>
drop table tblBooksEx
CREATE TABLE [tblBooksEx] (
[Row_ID] [int] IDENTITY (1, 1) NOT NULL ,
[BooksData] [text] COLLATE Polish_CI_AS NULL ,
CONSTRAINT [PK__tblBooksEx__17036CC0] PRIMARY KEY CLUSTERED
(
[Row_ID]
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
insert into tblBooksEx(booksdata) values('')
exec master..xp_cmdshell 'TextCopy.exe /S serv /U usr /Ppsv /D Northwind
/T
tblBooksEx /C BooksData /F c:\SCN.xml /W "WHERE Row_ID=1" /I'
>
>
/*PART 1*/
DECLARE @.id int
DECLARE @.idoc int
SET @.id = 1 -- or whatever the id
>
DECLARE @.datalen int
DECLARE @.sql varchar(8000)
DECLARE @.sql1 varchar(8000)
DECLARE @.cnt int
-- get the length
SELECT @.datalen = DATALENGTH (booksdata) / 4000 + 1 FROM tblBooksEx WHERE
row_id = @.id
>
-- phase 1 collect into @.sql declarations of @.str1, @.str2,...@.strn
SET @.cnt = 1
SET @.sql='DECLARE '
SET @.sql1 = ''
WHILE (@.cnt <= @.datalen)
BEGIN
SELECT
@.sql = @.sql + CASE @.cnt
WHEN 1 THEN ''
ELSE ', ' + CHAR(13)
END
+ ' @.str'+CONVERT(varchar(10),@.cnt)+' VARCHAR(4000)'
SET @.cnt = @.cnt + 1
END
-- phase 2 collect into @.sql selection of chunks (takng care of length)
SET @.cnt = 1
WHILE (@.cnt <= @.datalen)
BEGIN
IF LEN(@.sql) < 7850
SELECT @.sql = @.sql + CHAR (13) +
'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
REPLACE(SUBSTRING(booksdata, ' +
CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
CHAR(39)+CHAR(39) ) ' +
'FROM tblBooksEx ' +
'WHERE row_id = ''' + cast(@.id as varchar) + ''''
ELSE
SELECT @.sql1 = @.sql1 + CHAR (13) +
'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
REPLACE(SUBSTRING(booksdata, ' +
CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
CHAR(39)+CHAR(39) ) ' +
'FROM tblBooksEx ' +
'WHERE row_id = ''' + cast(@.id as varchar) + ''''
SET @.cnt = @.cnt + 1
END
>
>
/*PART 2*/
-- phase 3 preparing the 2nd level dynamic sql
SELECT @.sql1 = @.sql1 + CHAR(13) + 'EXEC ('+ CHAR(13) + '''DECLARE @.idoc
int'+ CHAR(13) +
'EXEC sp_xml_preparedocument @.idoc OUT, ''' + '
SET @.cnt = 1
WHILE (@.cnt <= @.datalen)
BEGIN
SELECT @.sql1 = @.sql1 + CHAR (13) + '@.str' + CONVERT (varchar(10), @.cnt) +
'
+'
SET @.cnt = @.cnt + 1
END
SET @.sql1 = @.sql1 + ' ''' '
SET @.sql1 = @.sql1 + CHAR(13) + 'DECLARE idoc_cur CURSOR FOR SELECT
@.idoc'''
+CHAR(13) + ')'
--debug code
/*
PRINT @.sql
PRINT '@.sql length=' +convert(varchar(5),datalength(@.sql))
PRINT '----'
PRINT @.sql1
PRINT '@.sql1 length=' +convert(varchar(5),datalength(@.sql1))
*/
EXEC (@.sql + @.sql1)
OPEN idoc_cur
FETCH NEXT FROM idoc_cur into @.idoc
DEALLOCATE idoc_cur
>
>
>
>
select * from OpenXML(@.idoc, '//transfer/body', 2) WITH (ng int, nk int,
dw
nvarchar(50))
--When Complete
--/*
exec sp_xml_removedocument @.idoc
--*/
>
How to solve this problem??
>
>
Best Regards
AJA
>


--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com http://www.greenms.com/sqlserver.html|||>Hello

Quote:

Originally Posted by

Quote:

Originally Posted by

>I have problem with reading from XML when XML is to large.
>Program delare 1-n variables where is declaration but can no make more
>delarations than length 8000 :((


>
If this is SQL 2005, try varchar(max)


Sorry i forgot tell its MSSQL 2k :(( any other idea?

AJA

Quote:

Originally Posted by

>
>

Quote:

Originally Posted by

>>
>drop table tblBooksEx
>CREATE TABLE [tblBooksEx] (
>[Row_ID] [int] IDENTITY (1, 1) NOT NULL ,
>[BooksData] [text] COLLATE Polish_CI_AS NULL ,
>CONSTRAINT [PK__tblBooksEx__17036CC0] PRIMARY KEY CLUSTERED
>(
> [Row_ID]
>) ON [PRIMARY]
>) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
>GO
>insert into tblBooksEx(booksdata) values('')
>exec master..xp_cmdshell 'TextCopy.exe /S serv /U usr /Ppsv /D Northwind
>/T
>tblBooksEx /C BooksData /F c:\SCN.xml /W "WHERE Row_ID=1" /I'
>>
>>
>/*PART 1*/
>DECLARE @.id int
>DECLARE @.idoc int
>SET @.id = 1 -- or whatever the id
>>
>DECLARE @.datalen int
>DECLARE @.sql varchar(8000)
>DECLARE @.sql1 varchar(8000)
>DECLARE @.cnt int
>-- get the length
>SELECT @.datalen = DATALENGTH (booksdata) / 4000 + 1 FROM tblBooksEx WHERE
>row_id = @.id
>>
>-- phase 1 collect into @.sql declarations of @.str1, @.str2,...@.strn
>SET @.cnt = 1
>SET @.sql='DECLARE '
>SET @.sql1 = ''
>WHILE (@.cnt <= @.datalen)
>BEGIN
>SELECT
>@.sql = @.sql + CASE @.cnt
>WHEN 1 THEN ''
>ELSE ', ' + CHAR(13)
>END
>+ ' @.str'+CONVERT(varchar(10),@.cnt)+' VARCHAR(4000)'
>SET @.cnt = @.cnt + 1
>END
>-- phase 2 collect into @.sql selection of chunks (takng care of length)
>SET @.cnt = 1
>WHILE (@.cnt <= @.datalen)
>BEGIN
>IF LEN(@.sql) < 7850
>SELECT @.sql = @.sql + CHAR (13) +
>'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
>REPLACE(SUBSTRING(booksdata, ' +
>CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
>CHAR(39)+CHAR(39) ) ' +
>'FROM tblBooksEx ' +
>'WHERE row_id = ''' + cast(@.id as varchar) + ''''
>ELSE
>SELECT @.sql1 = @.sql1 + CHAR (13) +
>'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
>REPLACE(SUBSTRING(booksdata, ' +
>CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
>CHAR(39)+CHAR(39) ) ' +
>'FROM tblBooksEx ' +
>'WHERE row_id = ''' + cast(@.id as varchar) + ''''
>SET @.cnt = @.cnt + 1
>END
>>
>>
>/*PART 2*/
>-- phase 3 preparing the 2nd level dynamic sql
>SELECT @.sql1 = @.sql1 + CHAR(13) + 'EXEC ('+ CHAR(13) + '''DECLARE @.idoc
>int'+ CHAR(13) +
>'EXEC sp_xml_preparedocument @.idoc OUT, ''' + '
>SET @.cnt = 1
>WHILE (@.cnt <= @.datalen)
>BEGIN
>SELECT @.sql1 = @.sql1 + CHAR (13) + '@.str' + CONVERT (varchar(10), @.cnt) +
>'
>+'
>SET @.cnt = @.cnt + 1
>END
>SET @.sql1 = @.sql1 + ' ''' '
>SET @.sql1 = @.sql1 + CHAR(13) + 'DECLARE idoc_cur CURSOR FOR SELECT
>@.idoc'''
>+CHAR(13) + ')'
>--debug code
>/*
>PRINT @.sql
>PRINT '@.sql length=' +convert(varchar(5),datalength(@.sql))
>PRINT '----'
>PRINT @.sql1
>PRINT '@.sql1 length=' +convert(varchar(5),datalength(@.sql1))
>*/
>EXEC (@.sql + @.sql1)
>OPEN idoc_cur
>FETCH NEXT FROM idoc_cur into @.idoc
>DEALLOCATE idoc_cur
>>
>>
>>
>>
>select * from OpenXML(@.idoc, '//transfer/body', 2) WITH (ng int, nk int,
>dw
>nvarchar(50))
>--When Complete
>--/*
>exec sp_xml_removedocument @.idoc
>--*/
>>
>How to solve this problem??
>>
>>
>Best Regards
>AJA
>>


>
--
Greg Moore
SQL Server DBA Consulting Remote and Onsite available!
Email: sql (at) greenms.com
http://www.greenms.com/sqlserver.html
>
>

|||On Mar 28, 4:05 pm, "AJA" <ajanospa...@.gazeta.plwrote:

Quote:

Originally Posted by

Hello
I have problem with reading from XML when XML is to large.
Program delare 1-n variables where is declaration but can no make more
delarations than length 8000 :((
>
drop table tblBooksEx
CREATE TABLE [tblBooksEx] (
[Row_ID] [int] IDENTITY (1, 1) NOT NULL ,
[BooksData] [text] COLLATE Polish_CI_AS NULL ,
CONSTRAINT [PK__tblBooksEx__17036CC0] PRIMARY KEY CLUSTERED
(
[Row_ID]
) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
insert into tblBooksEx(booksdata) values('')
exec master..xp_cmdshell 'TextCopy.exe /S serv /U usr /Ppsv /D Northwind /T
tblBooksEx /C BooksData /F c:\SCN.xml /W "WHERE Row_ID=1" /I'
>
/*PART 1*/
DECLARE @.id int
DECLARE @.idoc int
SET @.id = 1 -- or whatever the id
>
DECLARE @.datalen int
DECLARE @.sql varchar(8000)
DECLARE @.sql1 varchar(8000)
DECLARE @.cnt int
-- get the length
SELECT @.datalen = DATALENGTH (booksdata) / 4000 + 1 FROM tblBooksEx WHERE
row_id = @.id
>
-- phase 1 collect into @.sql declarations of @.str1, @.str2,...@.strn
SET @.cnt = 1
SET @.sql='DECLARE '
SET @.sql1 = ''
WHILE (@.cnt <= @.datalen)
BEGIN
SELECT
@.sql = @.sql + CASE @.cnt
WHEN 1 THEN ''
ELSE ', ' + CHAR(13)
END
+ ' @.str'+CONVERT(varchar(10),@.cnt)+' VARCHAR(4000)'
SET @.cnt = @.cnt + 1
END
-- phase 2 collect into @.sql selection of chunks (takng care of length)
SET @.cnt = 1
WHILE (@.cnt <= @.datalen)
BEGIN
IF LEN(@.sql) < 7850
SELECT @.sql = @.sql + CHAR (13) +
'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
REPLACE(SUBSTRING(booksdata, ' +
CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
CHAR(39)+CHAR(39) ) ' +
'FROM tblBooksEx ' +
'WHERE row_id = ''' + cast(@.id as varchar) + ''''
ELSE
SELECT @.sql1 = @.sql1 + CHAR (13) +
'SELECT @.str' + CONVERT(VARCHAR(10), @.cnt) + ' =
REPLACE(SUBSTRING(booksdata, ' +
CONVERT(VARCHAR(30), (@.cnt-1)*4000+1) + ', 4000),CHAR(39),
CHAR(39)+CHAR(39) ) ' +
'FROM tblBooksEx ' +
'WHERE row_id = ''' + cast(@.id as varchar) + ''''
SET @.cnt = @.cnt + 1
END
>
/*PART 2*/
-- phase 3 preparing the 2nd level dynamic sql
SELECT @.sql1 = @.sql1 + CHAR(13) + 'EXEC ('+ CHAR(13) + '''DECLARE @.idoc
int'+ CHAR(13) +
'EXEC sp_xml_preparedocument @.idoc OUT, ''' + '
SET @.cnt = 1
WHILE (@.cnt <= @.datalen)
BEGIN
SELECT @.sql1 = @.sql1 + CHAR (13) + '@.str' + CONVERT (varchar(10), @.cnt) + '
+'
SET @.cnt = @.cnt + 1
END
SET @.sql1 = @.sql1 + ' ''' '
SET @.sql1 = @.sql1 + CHAR(13) + 'DECLARE idoc_cur CURSOR FOR SELECT @.idoc'''
+CHAR(13) + ')'
--debug code
/*
PRINT @.sql
PRINT '@.sql length=' +convert(varchar(5),datalength(@.sql))
PRINT '----'
PRINT @.sql1
PRINT '@.sql1 length=' +convert(varchar(5),datalength(@.sql1))
*/
EXEC (@.sql + @.sql1)
OPEN idoc_cur
FETCH NEXT FROM idoc_cur into @.idoc
DEALLOCATE idoc_cur
>
select * from OpenXML(@.idoc, '//transfer/body', 2) WITH (ng int, nk int, dw
nvarchar(50))
--When Complete
--/*
exec sp_xml_removedocument @.idoc
--*/
>
How to solve this problem??
>
Best Regards
AJA


If you make an SP(stored Procedure) out of the Code , you can send
xml to SP as a text parameter|||

Quote:

Originally Posted by

If you make an SP(stored Procedure) out of the Code , you can send
xml to SP as a text parameter
>


Can you tell me clearly because i do not understand ..

AJA|||On Mar 29, 4:05 pm, "AJA" <ajanospa...@.gazeta.plwrote:

Quote:

Originally Posted by

Quote:

Originally Posted by

If you make an SP(stored Procedure) out of the Code , you can send
xml to SP as a text parameter


>
Can you tell me clearly because i do not understand ..
>
AJA


Need to do in an SP . You need to send text from client side. Sending
text within sql server not possible for SQL 2000

create proc usp_getxml
@.xmltext TEXT
as
Declare @.hdoc INT
--Create XML document.
EXEC sp_xml_preparedocument @.hdoc OUTPUT, @.xmltext