Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Convert iseries field to sql column

Author  Topic 

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 14:15:43
I am trying to use a sql select command to select a field name called "Docket#" from a file on the iseries and convert it to a column in sql server 2005. Apparently # is a wildcard in sql and I can not figure out how to write the select statement without getting an error about the #. Any help would be greatly appreciated.

Thanks

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-09 : 14:21:00
SELECT [Docket#]

OR

SELECT "Docket#"



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 14:26:11
Thanks for the response, unfortunately when I type:
SELECT "DOCKET#"
FROM SMPXXLIB.XXXCP50P
I get this error:
Error in Select clause: expression near "".
Unable to parse query text.


I also tried the other method you suggested and got an error also.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-09 : 14:43:23
can you post the table ddl?

do you know how to sript it from ssms or enterprise manager?

what version of sql server are you using?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 14:50:40
Sorry, I'm using VS2008 and sql server 2005. In VS, I connect to the iseries and use a dataset to drag/drop database tables and write Fill commands to retrieve my information. However, because this iseries table has a column named "Docket#", I can not drag/drop, so I created a generic table in my dataset and am only trying to retrieve Docket#. I have a datagridview on my form with the bindingsource set to that table in my dataset and I can use the following select statement but it simple writes "Docket#" in every single row of the datagridview:

SELECT 'DOCKET#' AS Expr1
FROM SMPXXLIB.XXXCP50P

The single quotes were put in automatically when I aliased it. This select statement does not give an error but like I said, it only writes "Docket#" in every row of the datagridview.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-09 : 15:04:00
So I guess this is a C# or vb.net question?

I would suggest you start writing stored procedures and calling them...

Other than that, sorry...can't help

Maybe someone else

Or try posting here

http://www.sqlteam.com/forums/forum.asp?FORUM_ID=17

Or here

http://www.dbforums.com/data-access-manipulation-batch-languages/




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 15:06:02
Correct, this is vb.net. I'm sure theres a way to do this, I just dont know how yet. Thanks for taking time to try and help though, much appreciated!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-09 : 15:20:41
Use [ and ] around column name.

SELECT [DOCKET#]
FROM SMPXXLIB.XXXCP50P



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 15:24:23
When I use this:

SELECT [DOCKET#]
FROM SMPXXLIB.XXXCP50P

I get this error:

Error in select clause: expression near '['.
Unable to parse text.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-09 : 15:28:26
I am stumped about you saying # is a wildcard character...
Tried this and it worked without any column delimiter
create table #temp (docket# int)
insert #temp values(2000)
select docket# from #temp
drop table #temp



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 15:35:55
I assumed it was a wildcard based on the error I was getting, maybe it is a reserved character or something. I'm not doing a create table or insert, I'm using a fill command in the tableadapter of a datatable so all I have to do is write the select statement and use vb.net to access the data. The file I am having problems with is an iseries file yet I have other iseries files (without the # in the field names) that are just fine. Every iseries file with a # in a field name will not let me build the select statement.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-09 : 15:37:09
what driver are you using? client access?
Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 15:39:53
Yes I believe client access to access the iseries and oledb tableadapter.
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-07-09 : 15:41:38
quote:
Originally posted by Peso

Use [ and ] around column name.

SELECT [DOCKET#]
FROM SMPXXLIB.XXXCP50P



N 56°04'39.26"
E 12°55'05.63"




Brilliant...and only an hour later...

Go on vacation already



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 15:43:34
I'm not exactly sure what you mean by that.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-09 : 15:44:04


No offense, but I thought it was worth to post again, since OP didn't mention he tried it in his efforts.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 15:45:53
I appreciate you trying to help, thanks!
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-09 : 15:50:45
how are you building your select statement? i suspect a .Net syntax error. what if you echo the query?

by the way "#" is not a special character in DB2.

SELECT docket# should work. SELECT "docket#" should also work. Seems something else is going on
Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 15:55:04
I'm not sure what it means to echo the query but in terms of building my select statement, I simply right click on the tableadapter in the dataset and take the option to create a new query. At that point I use the query builder to select my table and fields that I want to select and the select statement is automatically built. The 2 examples you gave do build correctly in terms of the select statement however when I run this project, I do not get the docket numbers I am looking for...every row in the grid (remember I am only returning docket#) has "Docket#" in it, not actualy numbers.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-07-09 : 15:59:54
try writing the query instead of letting the gui do it for you.

by echoing the query, i mean print it to the screen so you/we can examine it more closely. you need to know what IS being passed to the dbms, not what you THINK is being passed
Go to Top of Page

Daninpa
Starting Member

13 Posts

Posted - 2009-07-09 : 16:06:46
I still got the same result: "Docket#" in every single row. I'm not sure how to tell what is being passed as I am only using a fill command, I'm not passing any parameters.
Go to Top of Page
    Next Page

- Advertisement -