I use Server2000 and ADO connection and Unicode.
I have fields type of nvarchar.
And when I do the search ADO creates the SQL statement like this:
exec sp_executesql N'SELECT * FROM dbo.AB_Entities ab_e (NOLOCK) INNER JOIN
dbo.AB_EntityTreeNodeLink ab_etl (NOLOCK) ON
ab_e.EntityId=ab_etl.ChildEntityId WHERE ( ab_e.EntityCluster = @.P1) AND (
ab_e.EntityTitle = @.P2 AND ab_e.EntityType = @.P3) ', N'@.P1 int,@.P2
nvarchar(120),@.P3 smallint', 0, N'?', 7
(Caught from Profiler)
And this result nothing.
but when I delete the N from the second parameter:
..., N'@.P1 int,@.P2 nvarchar(120),@.P3 smallint', 0, '?', 7 <-- no N
before the Unicode variable, it works (work - means result the correct
records)!
and to make it more odd
..., N'@.P1 int,@.P2 nvarchar(120),@.P3 smallint', 0, N'John', 7 -- with N
works too.
I have tested those statements on S2k Query Analyzer and S2k5 SQL Server
Management Studio Express and there are same results.
Have anyone any idea what is wrong?
Regards,
Tomasz RutkowskiHi Tom
My guess is that your data is not what you expect
If you update the data
BEGIN TRANSACTION
UPDATE dbo.AB_EntityTreeNodeLink
SET EntityTitle = N'?'
WHERE EntityTitle = '?'
exec sp_executesql N'SELECT * FROM dbo.AB_Entities ab_e (NOLOCK) INNER JOIN
dbo.AB_EntityTreeNodeLink ab_etl (NOLOCK) ON
ab_e.EntityId=ab_etl.ChildEntityId WHERE ( ab_e.EntityCluster = @.P1) AND (
ab_e.EntityTitle = @.P2 AND ab_e.EntityType = @.P3) ', N'@.P1 int,@.P2
nvarchar(120),@.P3 smallint', 0, N'?', 7
ROLLBACK TRANSACTION
Does it work?
John
"TomX" wrote:
> I use Server2000 and ADO connection and Unicode.
> I have fields type of nvarchar.
> And when I do the search ADO creates the SQL statement like this:
> exec sp_executesql N'SELECT * FROM dbo.AB_Entities ab_e (NOLOCK) INNER JOIN
> dbo.AB_EntityTreeNodeLink ab_etl (NOLOCK) ON
> ab_e.EntityId=ab_etl.ChildEntityId WHERE ( ab_e.EntityCluster = @.P1) AND (
> ab_e.EntityTitle = @.P2 AND ab_e.EntityType = @.P3) ', N'@.P1 int,@.P2
> nvarchar(120),@.P3 smallint', 0, N'?', 7
> (Caught from Profiler)
> And this result nothing.
> but when I delete the N from the second parameter:
> ...., N'@.P1 int,@.P2 nvarchar(120),@.P3 smallint', 0, '?', 7 <-- no N
> before the Unicode variable, it works (work - means result the correct
> records)!
> and to make it more odd
> ..., N'@.P1 int,@.P2 nvarchar(120),@.P3 smallint', 0, N'John', 7 -- with N
> works too.
> I have tested those statements on S2k Query Analyzer and S2k5 SQL Server
> Management Studio Express and there are same results.
> Have anyone any idea what is wrong?
> Regards,
> Tomasz Rutkowski
>
>
>
Showing posts with label server2000. Show all posts
Showing posts with label server2000. Show all posts
Friday, March 23, 2012
Monday, February 20, 2012
ODBC for MS SQL server to access stored procedure
I have a stored procedure written in MS SQL Server2000 which takes argument(OUTPUT) as a cursor, and fills in the cursor with the record from the table.
I have to run this stored procedure from my C application program running in SUN OS2.9 with the help of ODBC calls.
Can anyone guide me through steps as to how to run the store procedure from my C program and receive records with the help of the cursor.
The store procedure is as follows
CREATE PROCEDURE testCursor @.xyzCursor cursor varying OUT AS
DECLARE temp CURSOR
LOCAL
FOR SELECT * FROM table
OPEN temp
SET @.xyzCursor=temp
RETURN(0)
GOMy first guess is that your design (having a stored procedure return a cursor) is going to run VERY poorly on an MS-SQL Server (or any relational database). MS-SQL is intended to do sets of data efficiently (which it does), but it doesn't do unit-record processing well.
Can you explain in a bit more detail what it is that you want to accomplish, and I'm sure that one of us can suggest a better relational design.
-PatP|||Ok I have table with few columns and from my C application I need to fetch records from that table using ODBC api's.
I agree that it would run poorly but was trying out different methods of retrieving records from the table into my C application before impleting the design.
Now using the CURSOR is one of the way which I had no idea how to handle in my C code.
I mean how to use ODBC api's to get those records?|||To read some rows from a table with the ODBC API in C++, you need to do the following (a cursor is not needed):
1. Run the SELECT query using either SQLExecDirect(), or SQLPrepare() / SQLExecute()
2. Call SQLFetch() in a loop until false. Each call will retrieve 1 row.
But in order for these functions to work, you need to call SQLConnect(), SQLBindCol(), SQLBindParameter(), etc in order to set things up.
If you google for these keywords you can track down some sample programs.
I have to run this stored procedure from my C application program running in SUN OS2.9 with the help of ODBC calls.
Can anyone guide me through steps as to how to run the store procedure from my C program and receive records with the help of the cursor.
The store procedure is as follows
CREATE PROCEDURE testCursor @.xyzCursor cursor varying OUT AS
DECLARE temp CURSOR
LOCAL
FOR SELECT * FROM table
OPEN temp
SET @.xyzCursor=temp
RETURN(0)
GOMy first guess is that your design (having a stored procedure return a cursor) is going to run VERY poorly on an MS-SQL Server (or any relational database). MS-SQL is intended to do sets of data efficiently (which it does), but it doesn't do unit-record processing well.
Can you explain in a bit more detail what it is that you want to accomplish, and I'm sure that one of us can suggest a better relational design.
-PatP|||Ok I have table with few columns and from my C application I need to fetch records from that table using ODBC api's.
I agree that it would run poorly but was trying out different methods of retrieving records from the table into my C application before impleting the design.
Now using the CURSOR is one of the way which I had no idea how to handle in my C code.
I mean how to use ODBC api's to get those records?|||To read some rows from a table with the ODBC API in C++, you need to do the following (a cursor is not needed):
1. Run the SELECT query using either SQLExecDirect(), or SQLPrepare() / SQLExecute()
2. Call SQLFetch() in a loop until false. Each call will retrieve 1 row.
But in order for these functions to work, you need to call SQLConnect(), SQLBindCol(), SQLBindParameter(), etc in order to set things up.
If you google for these keywords you can track down some sample programs.
Subscribe to:
Posts (Atom)