Showing posts with label backed. Show all posts
Showing posts with label backed. Show all posts

Sunday, March 11, 2012

Complicated join question.

Hi there.

I'm running Microsoft Business Solutions GP 8 backed by SQL Server 2000. I need to write a little C#/.NET 2.0 app to go "behind the scenes" to the SQL server in order to fetch and alter some data.

Unfortunately, the tables that GP 8 has created seem strange to me; I've encountered an issue with a SELECT clause featuring two INNER JOINs.

I need to select columns from three different tables. Unfortunately, the key structure of these tables is strange at best. You may view the structure of the three tables from the following URL.

http://pastebin.com/732226

My SQL query is as follows.

SELECT IV30400.DOCNUMBR, IV30300.DOCDATE, IV30200.GLPOSTDT, IV30400.SERLTNUM, IV30400.ITEMNMBR, IV30400.SERLTQTY

FROM IV30400

INNER JOIN IV30300 ON IV30300.DOCNUMBR = IV30400.DOCNUMBR

INNER JOIN IV30200 ON IV30200.DOCNUMBR = IV30300.DOCNUMBR

The key I am joining on is DOCNUMBR. The end result is that I get multiple copies of the same joint row in my result set. I only want one copy of each joint row.

Curiously, the DOCNUMBR key column does not contain unique values. In several rows (in each of the tables, mind you), the value in the DOCNUMBR column is identical. I don't know of this is the cause of my problem.

If anyone can help me sort out this thorny problem I would greatly appreciate it.

Thank you,

--JT

Curiously, the DOCNUMBR key column does not contain unique values. In several rows (in each of the tables, mind you), the value in the DOCNUMBR column is identical. I don't know of this is the cause of my problem.

I have seen programs like this and it is horrifying at best to work with the data (and this is their goal by making the table names so darn user friendly. I couldn't open your pictures, so you might just want to script them out.

Are there any queries in the program that give you somehting close to what you want? I used canned reports from the program I was working with to figure out the really hairy schema using Profiler (the greatest tool in the SQL Server toolbox.

Also, look to see if there is any table with docnumbr unique, of see if there is some other uniqueness criteria you can use.

|||

GROUP BY?

SELECT IV30400.DOCNUMBR, IV30300.DOCDATE, IV30200.GLPOSTDT, IV30400.SERLTNUM, IV30400.ITEMNMBR, IV30400.SERLTQTY

FROM IV30400

INNER JOIN IV30300 ON IV30300.DOCNUMBR = IV30400.DOCNUMBR

INNER JOIN IV30200 ON IV30200.DOCNUMBR = IV30300.DOCNUMBR

Group By IV30400.DOCNUMBR, IV30300.DOCDATE, IV30200.GLPOSTDT, IV30400.SERLTNUM, IV30400.ITEMNMBR, IV30400.SERLTQTY

Does that help at all?

Adamus

|||

Hi Adamus,

That indeed removed the duplicate result rows. I'm not sure WHY it works: I'm guessing that it's because the GROUP BY clause doesn't contain any sorting criteria, and thus it drops the duplicate rows altogether. Thank you for your suggestion!

Now I wonder why the tables are organized in this fashion. It almost seems counter-productive. Oh well.

Thanks again,

--JT

|||

Sounds like sloppy table design. Must've been crunched for time.

Adamus

Tuesday, February 14, 2012

Compatibility Level Question

I am a little confused on the importance of the Compatability Level setting.
I have a database originally created in SQL Server 2000 that I backed up and
then restored to SQL Server 2005. The compatibility level is currently set
at 80 (SQL 2000). I would like to change this to 90 (SQL 2005) but am not
sure of the ramifications of doing this. Can someone tell me of any negative
issues I should be aware of by doing this? I would like to treat this
database as if it were created as a SQL 2005 database (IOW, I don't need any
2000 support or compatibility).
Amos.Check out the description of sp_dbcmptlevel in the SQL 2005 Books Online for
a description of the behavior differences between 80 and 90. If you see not
changes that affect your app, you are probably ok but it's always a good
idea to test.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Amos Soma" <amos_j_soma@.yahoo.com> wrote in message
news:up7T4sgEGHA.2648@.TK2MSFTNGP11.phx.gbl...
>I am a little confused on the importance of the Compatability Level
>setting. I have a database originally created in SQL Server 2000 that I
>backed up and then restored to SQL Server 2005. The compatibility level is
>currently set at 80 (SQL 2000). I would like to change this to 90 (SQL
>2005) but am not sure of the ramifications of doing this. Can someone tell
>me of any negative issues I should be aware of by doing this? I would like
>to treat this database as if it were created as a SQL 2005 database (IOW, I
>don't need any 2000 support or compatibility).
> Amos.
>

Compatibility Level Question

I am a little confused on the importance of the Compatability Level setting.
I have a database originally created in SQL Server 2000 that I backed up and
then restored to SQL Server 2005. The compatibility level is currently set
at 80 (SQL 2000). I would like to change this to 90 (SQL 2005) but am not
sure of the ramifications of doing this. Can someone tell me of any negative
issues I should be aware of by doing this? I would like to treat this
database as if it were created as a SQL 2005 database (IOW, I don't need any
2000 support or compatibility).
Amos.
Check out the description of sp_dbcmptlevel in the SQL 2005 Books Online for
a description of the behavior differences between 80 and 90. If you see not
changes that affect your app, you are probably ok but it's always a good
idea to test.
Hope this helps.
Dan Guzman
SQL Server MVP
"Amos Soma" <amos_j_soma@.yahoo.com> wrote in message
news:up7T4sgEGHA.2648@.TK2MSFTNGP11.phx.gbl...
>I am a little confused on the importance of the Compatability Level
>setting. I have a database originally created in SQL Server 2000 that I
>backed up and then restored to SQL Server 2005. The compatibility level is
>currently set at 80 (SQL 2000). I would like to change this to 90 (SQL
>2005) but am not sure of the ramifications of doing this. Can someone tell
>me of any negative issues I should be aware of by doing this? I would like
>to treat this database as if it were created as a SQL 2005 database (IOW, I
>don't need any 2000 support or compatibility).
> Amos.
>

Compatibility Level Question

I am a little confused on the importance of the Compatability Level setting.
I have a database originally created in SQL Server 2000 that I backed up and
then restored to SQL Server 2005. The compatibility level is currently set
at 80 (SQL 2000). I would like to change this to 90 (SQL 2005) but am not
sure of the ramifications of doing this. Can someone tell me of any negative
issues I should be aware of by doing this? I would like to treat this
database as if it were created as a SQL 2005 database (IOW, I don't need any
2000 support or compatibility).
Amos.Check out the description of sp_dbcmptlevel in the SQL 2005 Books Online for
a description of the behavior differences between 80 and 90. If you see not
changes that affect your app, you are probably ok but it's always a good
idea to test.
Hope this helps.
Dan Guzman
SQL Server MVP
"Amos Soma" <amos_j_soma@.yahoo.com> wrote in message
news:up7T4sgEGHA.2648@.TK2MSFTNGP11.phx.gbl...
>I am a little confused on the importance of the Compatability Level
>setting. I have a database originally created in SQL Server 2000 that I
>backed up and then restored to SQL Server 2005. The compatibility level is
>currently set at 80 (SQL 2000). I would like to change this to 90 (SQL
>2005) but am not sure of the ramifications of doing this. Can someone tell
>me of any negative issues I should be aware of by doing this? I would like
>to treat this database as if it were created as a SQL 2005 database (IOW, I
>don't need any 2000 support or compatibility).
> Amos.
>