Multiple Datatable Select In C# And Sql?

May 10, 2008

Hello.

I have 2 diffrent tables in the database, is it possible to select both of those back to c# on the same time?

I DONT want to combine the tables, just select them into 2 diffrent datatables in one select statement?

At the moment, i have something like:

function XX
OpenDBCon();
mCom.Parameters.Clear();
mCom.CommandText = "Stuff_GetMovieCategories";
myAdap = new SqlDataAdapter();
myTable = new DataTable();
myAdap.SelectCommand = mCom;
myAdap.Fill(myTable);
CloseDBCon();
return myTable;

Can i ask the database to perhaos retrieve Stuff_GetMovieCategories and on the same time retrieve Stuff_MostViewedMovies?

So the SP does 2 select statements and returns them, i get in the function above 2 datatables with the information, one datatable with Categories and one table with MostViewedMovies.

Is this possible?

View 7 Replies


ADVERTISEMENT

DataTable.select Method

Oct 12, 2006

helloo

Can I use "like" in datatable.select method??

meaning:


Dim exp As String = "c.cDesc like " & txtSearch.Text & " + N'%' "
Dim rows() As DataRow = dtCenters.Select(exp)

knowing that txtSearch.text has unicode characters

View 1 Replies View Related

Using StoredProc With Multiple Result(or Datatable) In Server Reports

Sep 17, 2007

Hi guys,

I've been doing some LOCAL reports on my current application until recently there's has been a case that I really need to do SERVER reports.

Usually when I design my local reports, I create a XSD file, so I usually have one dataset with multiple tables in it. I just pass the dataset to report with a single procedure call that returns multiple result sets or data table.

From what I understood server reports are binded to database objects only, like stored procedures. Now I used the same stored procedure that I used in my local report to my server report. But the thing is only the first result set in the stored procedure is recognized. Are there anyway that I can bind the server report to a single stored procedure that return multiple result sets?

Thanks.

View 2 Replies View Related

Stored Procedures On SQL 2000 Compared To Dotnet's Datatable.select

Jul 20, 2005

Hi,Has any one ever compared the performance of calling a DataTable'sSelect method with a stored procedure doing the same thing?My point is:dataRows = DataTable.Select(filter) is better orPassing paramters to stored procedure?The datatable holds about 500-700 rows at any given time.If I select one of the approaches the business logic will go intorespective layers.With dotnet in picture what would be a good approach- Have the data in Datatable and do a filter on the data or callstored procedures which has been the convention.Can some one pl. suggest?

View 3 Replies View Related

Filling A DataTable From SqlQuery : If SqlQuery Returns Null Values Problem Ocurrs With DataTable

Sep 3, 2007

Filling a DataTable from SqlQuery : If SqlQuery returns some null values problem ocurrs with DataTable.
Is it possible using DataTable with some null values in it?
Thanks

View 2 Replies View Related

Multiple Tables Select Performance - SQL 2005 - Should It Take 90 Seconds For A Select?

Dec 4, 2007

I have a problem where my users complain that a select statement takes too long, at 90 seconds, to read 120 records out of a database.
The select statement reads from 9 tables three of which contain 1000000 records, the others contain between 100 and 250000 records.
I have checked that each column in the joins are indexed - they are (but some of them are clustered indexes, not unclustered).
I have run the SQL Profiler trace from the run of the query through the "Database Engine Tuning Advisor". That just suggested two statistics items which I added (no benefit) and two indexes for tables that are not involved at all in the query (I didn't add these).
I also ran the query through the Query window in SSMS with "Include Actual Execution Plan" enabled. This showed that all the execution time was being taken up by searches of the clustered indexes.
I have tried running the select with just three tables involved, and it completes fast. I added a fourth and it took 7 seconds. However there was no WHERE clause for the fourth table, so I got a cartesian product which might have explained the problem.
So my question is: Is it normal for such a type of read query to take 90 seconds to complete?
Is there anything I could do to speed it up.
Any other thoughts?
Thanks

View 7 Replies View Related

Using A Datatable In Sql

Dec 11, 2006

Hi I am trying to use the results of a datatable as an input to a ne SQL statement.
 The datatable is created and populted by the source below after previously creating MyLookupCommand
MyLookupReader = MyLookupCommand.ExecuteReader(CommandBehavior.CloseConnection)
Dim Mydatatable = New DataTable()
Mydatatable.Load(MyLookupReader)
 
I now create a new SQL string allong the lines of
SELECT tableA.field1 FROM TableA INNERJOIN Mydatatable ON tableA.field2 = Mydatatable.Filed9
 However I get the following error
 Invalid object name 'Mydatatable'.
Any suggestions on how to resolve this. 
 
possibley of interest is that I would have like to have done this in 1 SQL but the results in Mydatatable are from a SELECT DISTINCT and Field1 is a text filed that can't be used in a DISTINCT statement, hence using two statements.  
Many thanks in advance 
 

View 6 Replies View Related

Multiple Select In One Sp

Oct 25, 2007

 I was wondering if it's possible to have a stored procedure that has
two(or more) select statements which you can combine as a single result set.I am not able to use union as my select returns different number of columns.My selects are like this,This example is using only two table but i can have more then 2 tables in situation..ELECT     SUM(col1) AS sumcol1FROM         tbl1WHERE     (ID = @para1') SELECT     SUM(col1) AS sumcol1, SUM(col2) AS sumcol2, SUM(col3)                       AS sumcol3, SUM(col4) AS sumcol1FROM         tbl2WHERE     (id = @para1).thanks  

View 6 Replies View Related

Multiple Select

Dec 15, 2006

Hi,

In my report i have a paremeter which is a dropdown list showing alla available values.Now i want to select multiple values.The parameter is not multi valued.

From the following link:

http://www.ssw.com.au/ssw/Standards/BetterSoftwareSuggestions/ReportingServices.aspx#RichTexbox

Multiple select in Parameters Is fixed in Sqlserver reporting services 2005.

Iam using 2005 version,But i can't able to select multiple values by holding Ctrl key.How to achieve this.If we able to select the multiple values,In wgich format the selected value is passed to the Stored Procedure,It is same the way as selecting multiple values from Multi valued Parameter.

Please help me.

Thanks in advance

View 4 Replies View Related

Use DataTable As SQL Parameter

Jun 28, 2006

Hi,
I'm wondering if this is possible. I want to use a datatable as a parameter in my SQL query. The error I am getting is "No mapping exists from object type System.Data.DataColumn to a known managed provider native type."  Any help is appreciated.
 Here is the code.
Private Function GetAvailableTutors(ByVal qualifiedTutorsDataSet As DataTable) As DataTable
Dim TutorAvailabilityDataTable As DataTable = New DataTable()
Using myConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("ASC_Schedule").ConnectionString)
Dim myCommand As SqlCommand = _
New SqlCommand("SELECT TutorID, TimeIndex FROM T_Hours WHERE SessionID > 0 AND TutorID IN (@TutorList) AND DateDropped > GetDATE() ORDER By T_QualifiedTutors.TutorID", myConnection)
myCommand.Parameters.AddWithValue("@TutorList", qualifiedTutorsDataSet.Columns.Item("TutorID"))
Dim myDataAdapter3 As SqlDataAdapter = New SqlDataAdapter()
myDataAdapter3.SelectCommand = myCommand
myDataAdapter3.Fill(TutorAvailabilityDataTable)
Return TutorAvailabilityDataTable

End Using
End Function

View 2 Replies View Related

Datatable From Gridview

Aug 2, 2006

hi all
 
the usual way to bid a gridview is to data soursce
is there a way to do  the folowing , creat a data table from the gridview shown valus " currunt page "
 
thanks
 

View 1 Replies View Related

Constructing A Datatable

Dec 27, 2006

Hi,
I am experimenting to make a datatable in C# code in a page. This table should be a disconected table with Only valid for the present session.
I try the following code:
public partial class Default2 : System.Web.UI.Page
{
    DataTable DT = new DataTable("TEST");
   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataColumn Col1 = new DataColumn("Col1");
            Col1.DataType = typeof(Int32);
            Col1.AllowDBNull = false;
            DT.Columns.Add(Col1);
 
            DataColumn Col2 = new DataColumn("Col2");
            Col2.DataType = typeof(string);
            Col2.AllowDBNull = true;
            DT.Columns.Add(Col2);
 
            DataColumn Col3 = new DataColumn("Col3");
            Col3.DataType = typeof(DateTime);
            Col3.AllowDBNull = true;
            DT.Columns.Add(Col3);
 
            GridView1.DataSource = DT;
        }
    }
 
    protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 1; i < 20; i++)
        {
            DataRow MyRow = DT.NewRow();
            MyRow["Col1"] = i;
            DT.Rows.Add(MyRow);
        }
    }
}
For one reason or the other. if I click the button I get the message that Col1 dus not make part of the table TEST. It turns out that there are no columns added to the table. altroug the code in the page load part has been run. I suppose I have to do something with the session state to make my DataTable persistent, but I have no idea what. Can somebody help me out?
Thanks!
Rob

View 6 Replies View Related

Appending One Datatable To Another ?

Jun 1, 2007

Is the merge method, what will work in this case ?  I have two datatables with the exact same structure.  How can I append the rows from table 2 onto the bottom of table 1 ?  Is looping through the rows collection the only way ?

View 2 Replies View Related

SqlDataSource And DataTable

Sep 11, 2007

Hi,Is it possible to store data that is retrieved by SqlDataSource in a... let's say... DataTable? I mean, If I dragged and dropped a GridView and an SqlDataSource and then I set up those controls in page designer in Visual Studio, is it possible at some time later to retrieve the data retrieved by the SqlDataSource and then store the data in a DataTable?Best regards,Haris 

View 7 Replies View Related

DLINQ To DataTable ?

Dec 6, 2007

Is there a built in way of converting a LINQ qurey result into a DataTable or DataView ?

View 4 Replies View Related

How To Return The Datatable Value

Dec 26, 2007

 hai This is rameshi had a small doubt in this  public DataTable GetStatelist()    {        DataTable returnValue = null;        SqlCommand selcommand = new SqlCommand();        selcommand.CommandType = CommandType.Text;        selcommand.CommandText = "select * from USER_MASTER";        selcommand.Connection = _connectionobject;                    try         {                                 _connectionobject.Open();            DataSet ds = new DataSet();            SqlDataAdapter ada = new SqlDataAdapter(selcommand);            ada.Fill(ds);            _connectionobject.Close();            return returnValue; ;         }        catch (Exception exception)        {            if (_connectionobject.State == ConnectionState.Open)            {                _connectionobject.Close();            }            throw new Exception(exception.Message);        }        if (_connectionobject.State == ConnectionState.Open)        {            _connectionobject.Close();        }        return returnValue; ;     }    after compiling its show the return value is nullwhat is error in my codinghow i can return the value to the corresponding function   if (!IsPostBack)        {             GridView1.DataSource=database.GetStatelist();            GridView1.DataBind();        } i am waiting for the result 

View 4 Replies View Related

Datatable Is Empty

Feb 12, 2008

I am fetching records from a table and putting in a datatable using the "sqlda.fill(datatable)"
when i see the datable in "data visualizer" i find no rows.
It is confused eventhough it does not throw any error
 

View 3 Replies View Related

Datatable To Sqldatasource

May 2, 2008

Do I have to save the datatable into sqldatasource's SELECT results? if yes , how?

View 4 Replies View Related

Querying A Datatable

Mar 20, 2006

I have a table containing prices. This table will be queried very often to provide quotes for clients.So to ease the burden on the server I want to cache the table and then just query the cached version.However it seems that I can only cache the table as a datatable. This means I have to query the datatable to get the prices for each quote.I'm not sure how to query a datatable. Is ther syntax similar to querying a SQL table?In fact is this best way to go about things?Any help would be appreciated.G

View 4 Replies View Related

DataTable Query...

Aug 7, 2007



Hi...

In my appllication, i am having a DataTable... For that DataTable i have to write a query for a expression... This epression is more of mathematical expression type. Here is the sample expression-


(column1 < 1 && (column2 = 2 || column3 > 5) || column4 != 3)

How i can write a query for such a equation...? Is it possible to use logical & mathematical operator in the equation & to write a query for this type of equation... Is there is any good article on this...

Thanks in adavnce...

IamHuM










View 3 Replies View Related

Select Multiple Tables

Jul 9, 2007

Hi there,I want to select records from 3 tables. In SQL Server 2005, I'm using of "For XML" like this:Select *, (Select * From dbo.PageModules Where (PageId = 1) For Xml Auto) As Modules, (Select * From dbo.PageRoles Where (PageId = 1) For Xml Auto) As Roles From dbo.PagesThat works fine in SQL 2005 but not in SQL 2000, Because SQL 2000 does not support nested "FOR XML".Is there any way for selecting records from multiple tables by a query?Thanks in advance 

View 4 Replies View Related

USING MULTIPLE SELECT STATEMENTS

Apr 23, 2008

how can take codes below and put them into one store procedure to supplie a gridview. also i will like to define the row name on the left like i did to the column on the top using the 'AS'
 Code1....
SELECT
SUM(CASE WHEN Month = 'January' THEN 1 ELSE 0 END) AS January, SUM(CASE WHEN Month = 'February' THEN 1 ELSE 0 END) AS February,
SUM(CASE WHEN Month = 'March' THEN 1 ELSE 0 END) AS March, SUM(CASE WHEN Month = 'April' THEN 1 ELSE 0 END) AS April,
SUM(CASE WHEN Month = 'May' THEN 1 ELSE 0 END) AS May, SUM(CASE WHEN Month = 'June' THEN 1 ELSE 0 END) AS June,
SUM(CASE WHEN Month = 'July' THEN 1 ELSE 0 END) AS July, SUM(CASE WHEN Month = 'August' THEN 1 ELSE 0 END) AS August,
SUM(CASE WHEN Month = 'September' THEN 1 ELSE 0 END) AS September, SUM(CASE WHEN Month = 'October' THEN 1 ELSE 0 END) AS October,
SUM(CASE WHEN Month = 'November' THEN 1 ELSE 0 END) AS November, SUM(CASE WHEN Month = 'December' THEN 1 ELSE 0 END) AS December,
SUM(CASE WHEN site_descr = 'SITE1' THEN 1 ELSE 0 END) AS AllTotal
FROM dbo.V_results
WHERE (site_descr = 'SITE1')
 
Code2.....
 
SELECT
SUM(CASE WHEN Month = 'January' THEN 1 ELSE 0 END) AS January, SUM(CASE WHEN Month = 'February' THEN 1 ELSE 0 END) AS February,
SUM(CASE WHEN Month = 'March' THEN 1 ELSE 0 END) AS March, SUM(CASE WHEN Month = 'April' THEN 1 ELSE 0 END) AS April,
SUM(CASE WHEN Month = 'May' THEN 1 ELSE 0 END) AS May, SUM(CASE WHEN Month = 'June' THEN 1 ELSE 0 END) AS June,
SUM(CASE WHEN Month = 'July' THEN 1 ELSE 0 END) AS July, SUM(CASE WHEN Month = 'August' THEN 1 ELSE 0 END) AS August,
SUM(CASE WHEN Month = 'September' THEN 1 ELSE 0 END) AS September, SUM(CASE WHEN Month = 'October' THEN 1 ELSE 0 END) AS October,
SUM(CASE WHEN Month = 'November' THEN 1 ELSE 0 END) AS November, SUM(CASE WHEN Month = 'December' THEN 1 ELSE 0 END) AS December,
SUM(CASE WHEN site_descr = 'SITE2' THEN 1 ELSE 0 END) AS AllTotal
FROM dbo.V_results
WHERE (site_descr = 'SITE2')
 
 thanks in advance

View 10 Replies View Related

Multiple Select Statements

Dec 22, 2005

Hi guys and gals,
I am trying to create a select statement that will return an INT that I will later have to use in another select statement. I have the following code, however, I keep getting an error that says:
'Error116: Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.'
My Code is below:
//Start of sql
CREATE PROCEDURE ADMIN_GetSingleUsers( @userID  int) AS
DECLARE @userSQL intSET @userSQL = (SELECT User_ID, TITLE.TITLE AS TITLE,    Cast(Users.Active as  varchar(50)) as Active,   Cast(Users.Approved as  varchar(50)) as Approved,   Users.Unit_ID As usersUnitID,   *    From TITLE, Users   WHERE    User_ID = @userID AND   TITLE.TITLE_ID = Users.Title_ID )
Select Unit_ID, Parent_ID, Unit_Name from UNITS WHERE Unit_ID = @userSQL
//End of sql
Can you point to what I am doing wrong? Thanks in advance!

View 4 Replies View Related

Use Variables Or Multiple SELECT&#39;s?

Jun 6, 2000

Stored procedure retrieves a single row from a single table... Based on the specific values in 4 different columns, different branch actions are taken using 4 nested IF statements.

The question is, what is more efficient: storing column values in 4 variables and then evaluting each of them, or executing the same query 4 times?

Scenario A:

DECLARE @var1 char(20), @var2 char(20), @var3 char(20), @var4 char(20)
SELECT @var1 = col1, @var2 = col2, @var3 = col3, @var4 = col4
FROM theTable
WHERE rid = 12345
IF @var1 = 1
...
ELSE IF @var2 = 2
...
ELSE IF @var3 = 3
... etc.
---------------

Scenario B:

IF (SELECT col1 FROM theTable WHERE rid = 12345) = 1
...
ELSE IF (SELECT col2 FROM theTable WHERE rid = 12345) = 2
...
ELSE IF (SELECT col3 FROM theTable WHERE rid = 12345) = 3
... etc.
--------

Scenario A or B? Please advise...


TIA,
Alex

View 1 Replies View Related

Multiple Table Select

Jun 25, 2004

Hey everyone, I have a question regarding an SQL query. I'm working on a Web App in .NET at the moment and part of the project is to produce a report of all the information about the clients. Now, there are 4 tables in question: Client, Details, Appointments and RefItem. Now, a lot of the information stored in the first 3 tables are IDs and the names corresponding to those IDs are in the RefItem table.

The RefItem table has the columns ItemID, GroupID, Name, HelpText and Active. For example, a row in the Appoinment table might contain the ID 150 under the AppointmentStatusID. In RefItem, the ID 150 corresponds with "Scheduled". So I have


Code:

SELECT Name FROM RefItem WHERE RefItem.ItemID = Appointment.AppointmentStatusID



This works fine for selecting one name, but my report requires pretty much every name. I was told I'd had to use INNER JOIN or LEFT OUTER JOIN but I can't seem to figure it out. If anyone has any info, please let me know!! Thanks

View 4 Replies View Related

Multiple Nested (TOP 1 SELECT) S

Jun 1, 2006

Hi guys,

I have been struggling over the following problem for a few days... i was wondering if anyone could shed some light...!

I have the following query:

SELECT Field1, Field2
FROM Table1 INNER JOIN Table2 ON Table1.ID = Table2.ID
WHERE Table2.Field1 = ( SELECT TOP 1 Field1 FROM Table2 WHERE Field3='X' ORDER BY Date1)
AND Table2.Field2 = ( SELECT TOP 1 Field2 FROM Table2 WHERE Field3='X' ORDER BY Date1)

Is there a better way to do this. I was thinking of something very similar to the below query (Which doesnt work):

SELECT *
FROM Table1 A
INNER JOIN Table2 B ON (A.ID=B.ID)
INNER JOIN ( SELECT TOP 1 * FROM Table2 WHERE Field3='X' ORDER BY Date1 ) C ON (A.ID=C.ID)
WHERE
B.Field1 = C.Field1
B.Field2 = C.Field1

Any ideas?

Many thanks in advance,

TNT

View 2 Replies View Related

Select From Multiple Tables

Feb 24, 2012

I have three tables.

Table USERS Contains columns User_id and UserName
Table DOMAIN Contains columns Domain_id and DomainName
Table USER_DOMAIN Contains columns User_id, Domain_id, count, day, month, year

I am looking to run a report that pulls its information from USER_DOMAIN but instead of displaying User_id, Domain_id, it returns the UserName and DomainName associated.

The query to pull the info i need is very simple, where i am having problems is linking the user_id to the UserName and the Domain_id to the DomainName.

View 2 Replies View Related

Select Where LIKE From Multiple Columns

May 20, 2008

I am using mySQL and the following query works fine:

SELECT * from listings where name LIKE "%$trimmed%" order by name";

and so does this query:

SELECT * from listings where keywords LIKE "%$trimmed%" order by name";

however, I can't seem to combine the two with an OR statement as this query only returns the results from the first LIKE column

select * from listings where name LIKE "%$trimmed%" or keywords LIKE "%$trimmed%" order by name

I want to be able to search both columns and return a row if the NAME column or the KEYWORDS columns contains a string.

View 1 Replies View Related

SELECT On Multiple Tables Help

Jul 20, 2007

Hi all! I just registred (very nice site) and have problem with getting some data from multiple tables, I would like to get result in one result set and best would be in one sql query.

I have DB for miniMessenger proggy, what i try to do is retrieve list of contacts.

Table containing user account information.

CREATE TABLE `account` (
`id_account` mediumint(8) unsigned NOT NULL auto_increment,
`userdata_id` mediumint(8) unsigned NOT NULL default '0',
`login` varchar(15) NOT NULL default '',
`pwd` varchar(15) NOT NULL default '',
`messenger_id` mediumint(8) unsigned NOT NULL default '0',
`logged` tinyint(1) NOT NULL default '0',
`ost_login` varchar(11) default NULL,
PRIMARY KEY (`id_account`),
UNIQUE KEY `messenger_UN` (`messenger_id`),
UNIQUE KEY `userdata_UN` (`userdata_id`)
)

INSERT INTO `account` VALUES (1, 1, 'User', 'fatimah', 4118394, 0, NULL);
INSERT INTO `account` VALUES (2, 2, 'Admin', 'haslo', 3333333, 0, NULL);

Contact list, first field is contact number (like 4356789 - MESSENGER id) next to this number is its contact number, auth - if contact was authorised, ban selfexplained :) I just take every row with number 4356789 and get contact numbers next to it.
CREATE TABLE `contacts` (
`contact_id` mediumint(8) unsigned NOT NULL default '0',
`contacts` mediumint(8) unsigned NOT NULL default '0',
`auth` tinyint(1) unsigned NOT NULL default '0',
`ban` tinyint(1) unsigned NOT NULL default '0',
KEY `Contacts ID` (`contact_id`)
)
INSERT INTO `contacts` VALUES (4118394, 3333333, 1, 0);
INSERT INTO `contacts` VALUES (4118394, 1234567, 0, 1);

Its table for messenger data, ID, status of contact (offline,online,ect), description, chat archiwum,
CREATE TABLE `messenger` (
`id_messenger` mediumint(8) unsigned NOT NULL default '0',
`status_id` tinyint(3) unsigned NOT NULL default '0',
`description` varchar(255) NOT NULL default '',
`archiwum` mediumtext NOT NULL,
PRIMARY KEY (`id_messenger`)
)
INSERT INTO `messenger` VALUES (1234567, 0, '', '');
INSERT INTO `messenger` VALUES (3333333, 1, '', '');
INSERT INTO `messenger` VALUES (4118394, 2, '', '');

Status is enumeration of status states(off,on,brb ect).
CREATE TABLE `status` (
`id_status` tinyint(3) unsigned NOT NULL default '0',
`stat` varchar(15) default NULL,
PRIMARY KEY (`id_status`)
)
INSERT INTO `status` VALUES (0, 'offline');
INSERT INTO `status` VALUES (1, 'Online');
INSERT INTO `status` VALUES (2, 'brb');


What i want to get is contact list + additional info of specific user by its messenger id. Like:
id_messenger,contacts,auth,ban,stat

which is userID, contact ID, authorisation, ban, status

My query looks like this:
SELECT id_messenger,contacts,auth,ban,status_id
FROM account,messenger,contacts
WHERE account.login = 'User'
AND messenger.id_messenger = account.messenger_id
AND contacts.contact_id = messenger.id_messenger

And it shows in stat only status of user of which i retrieve contact list. Please help me, im tired of working on this, im sure it is trivial :(

thx in advance!

View 6 Replies View Related

Using Select * From Multiple Tables

Nov 8, 2007

Can someone explain to me why this would be considered "bad"? One thing that pops in my mind is that I really don't need all the columns from all these tables, only specific columns. Would this cause a performance issue when used in a stored proc for a transactional app?

SELECT *
FROM CASE_XREF CX, CASE_RENEWAL_XREF CRX, RENEWAL_BATCH RB, PROPOSAL P
WHERERB.MKT_SEG = @MKT_SEG
AND RB.CORP_ENT_CD = 'oh'
AND RB.RENEWAL_DT = '01/01/2008'
AND CRX.TRIGGER_TYPE_CD = 'P'
AND RB.BATCH_ID = CRX.BATCH_ID
AND CRX.CASE_ID = CX.CASE_ID
AND CRX.REN_PROSPECT_ID = P.PROSPECT_ID
AND CRX.REN_PROP_NUM = P.PROP_NUM
AND P.PROP_STATUS <> 'C'
AND CX.ACCT_NBR = 123152

View 5 Replies View Related

Select From Multiple Tables

Dec 18, 2007

I have four tables. now i need to select the rows from all the four tables.

TABLE1: -Job
jobno
mtid
prid
mtpath
prpath

TABLE2: - livestaff this id will be store in Job
staffid
staffname
teamid
active


TABLE3: -masterstaff
mstaffid
staffname
teamid
active


TABLE4: -staffrel
masterstaffid
livestaffid

Now i need to select * from job and staffname from masterstaff and teamid from livestaff.

Please help

____________
Praba

View 2 Replies View Related

Multiple Multi Select And T SQL

Sep 7, 2007

I'm looking to see if there are any best known methods or better ways of handling multiple multi select parameters in reports coming from reporting services.

It's not a big deal to account for this in T-SQL when there are only a few multi-select boxes but each new one that I add creates a whole bunch more work for me. Each of these multiselect list boxes are optional filters for the report. The way that I"m handling it today is as follows:

I'm turning the multi-select lists into comma seperated variables and then using Itzik Ben-Gan's split UDF to turn them into tables that I can join to my query. I then take the base query w/out the joins and pass that into a temp table. Then I start a bunch of IF THEN program flow to either JOIN or not JOIN the results of the split UDF.

Here is my example scenarios:
Assumptions:


I have a report that has 5 input drop down lists in reporting services.

I have a user stored procedure that takes the multi-select comma seperated list and turns it into a table variable.

I cannot use Dynamic SQL because of information security policy.

The multi-select lists are optional parameters.

The Code below is accurate.... I didn't test it and just wrote it quickly to show the complexity... hopefully you get the idea.


In scenario 1: One of the drop down lists are multi-select enabled.
My SQL Sproc Would look like this:

CREATE PROCEDURE [dbo].[get_my_ssrs_data]

@Origin_Warehouse_IDs varchar(max) = '',
@Ship_To_Geo_IDs varchar(max) = '',
@Sold_To_Geo_IDs varchar(max) = '',
@Customer_Type_IDs varchar(max) = ''

WITH RECOMPILE

AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID(N'tempdb..#MyCoreTemp', N'U') IS NOT NULL DROP TABLE #MyCoreTemp;

SELECT
Origin_Warehouse_ID
, Ship_To_Geo_ID
, Sold_To_Geo_ID
, Customer_Type_ID

INTO #MyCoreTemp

FROM
My_Fact_Table

IF @Origin_Warehouse_IDs = ''
BEGIN
SELECT * FROM #MyCoreTemp
END
ELSE
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Origin_Warehouse_IDs,DEFALUT) OW ON (MCT.Origin_Warehouse_ID = OW.nstr)
END


In scenario 2: Two of the drop down lists are multi-select enabled.
My SQL Sproc Would look like this:

CREATE PROCEDURE [dbo].[get_my_ssrs_data]

@Origin_Warehouse_IDs varchar(max) = '',
@Ship_To_Geo_IDs varchar(max) = '',
@Sold_To_Geo_IDs varchar(max) = '',
@Customer_Type_IDs varchar(max) = ''

WITH RECOMPILE

AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID(N'tempdb..#MyCoreTemp', N'U') IS NOT NULL DROP TABLE #MyCoreTemp;

SELECT
Origin_Warehouse_ID
, Ship_To_Geo_ID
, Sold_To_Geo_ID
, Customer_Type_ID

INTO #MyCoreTemp

FROM
My_Fact_Table

IF @Origin_Warehouse_IDs = '' AND @Ship_To_Geo_IDs = ''
BEGIN
SELECT * FROM #MyCoreTemp
END
ELSE
IF @Origin_Warehouse_IDs != '' AND @Ship_To_Geo_IDs = ''
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Origin_Warehouse_IDs,DEFALUT) OW ON (MCT.Origin_Warehouse_ID = OW.nstr)
END
ELSE
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Origin_Warehouse_IDs,DEFALUT) OW ON (MCT.Origin_Warehouse_ID = OW.nstr)
JOIN udfSplit(@Ship_To_Geo_IDs,DEFALUT) STG ON (MCT.Ship_To_Geo_ID = STG.nstr)
END


In scenario 3: Three of the drop down lists are multi-select enabled.
My SQL Sproc Would look like this:

CREATE PROCEDURE [dbo].[get_my_ssrs_data]

@Origin_Warehouse_IDs varchar(max) = '',
@Ship_To_Geo_IDs varchar(max) = '',
@Sold_To_Geo_IDs varchar(max) = '',
@Customer_Type_IDs varchar(max) = ''

WITH RECOMPILE

AS
BEGIN
SET NOCOUNT ON;
IF OBJECT_ID(N'tempdb..#MyCoreTemp', N'U') IS NOT NULL DROP TABLE #MyCoreTemp;

SELECT
Origin_Warehouse_ID
, Ship_To_Geo_ID
, Sold_To_Geo_ID
, Customer_Type_ID

INTO #MyCoreTemp

FROM
My_Fact_Table

IF @Origin_Warehouse_IDs = '' AND @Ship_To_Geo_IDs = '' AND @Customer_Type_IDs = ''
BEGIN
SELECT * FROM #MyCoreTemp
END
ELSE
IF @Origin_Warehouse_IDs != '' AND @Ship_To_Geo_IDs = '' AND @Customer_Type_IDs = ''
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Origin_Warehouse_IDs,DEFALUT) OW ON (MCT.Origin_Warehouse_ID = OW.nstr)
END
ELSE
IF @Origin_Warehouse_IDs != '' AND @Ship_To_Geo_IDs != '' AND @Customer_Type_IDs = ''
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Origin_Warehouse_IDs,DEFALUT) OW ON (MCT.Origin_Warehouse_ID = OW.nstr)
JOIN udfSplit(@Ship_To_Geo_IDs,DEFALUT) STG ON (MCT.Ship_To_Geo_ID = STG.nstr)
END
ELSE
IF @Origin_Warehouse_IDs = '' AND @Ship_To_Geo_IDs != '' AND @Customer_Type_IDs != ''
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Ship_To_Geo_IDs,DEFALUT) STG ON (MCT.Ship_To_Geo_ID = STG.nstr)
JOIN udfSplit(@Customer_Type_IDs,DEFALUT) CT ON (MCT.Customer_Type_ID = CT.nstr)
END
ELSE
IF @Origin_Warehouse_IDs != '' AND @Ship_To_Geo_IDs = '' AND @Customer_Type_IDs != ''
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Origin_Warehouse_IDs,DEFALUT) OW ON (MCT.Origin_Warehouse_ID = OW.nstr)
JOIN udfSplit(@Customer_Type_IDs,DEFALUT) CT ON (MCT.Customer_Type_ID = CT.nstr)
END
ELSE
IF @Origin_Warehouse_IDs = '' AND @Ship_To_Geo_IDs = '' AND @Customer_Type_IDs != ''
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Customer_Type_IDs,DEFALUT) CT ON (MCT.Customer_Type_ID = CT.nstr)
END
ELSE
IF @Origin_Warehouse_IDs = '' AND @Ship_To_Geo_IDs != '' AND @Customer_Type_IDs = ''
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Ship_To_Geo_IDs,DEFALUT) STG ON (MCT.Ship_To_Geo_ID = STG.nstr)
END
ELSE
BEGIN
SELECT * FROM #MyCoreTemp MCT
JOIN udfSplit(@Origin_Warehouse_IDs,DEFALUT) OW ON (MCT.Origin_Warehouse_ID = OW.nstr)
JOIN udfSplit(@Ship_To_Geo_IDs,DEFALUT) STG ON (MCT.Ship_To_Geo_ID = STG.nstr)
JOIN udfSplit(@Customer_Type_IDs,DEFALUT) CT ON (MCT.Customer_Type_ID = CT.nstr)
END



END


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

As you can see by scenario 3 where there are only 3 multi-select lists it gets really hairy. If I go to a forth it will be even worse. Does anyone know of another better way to do this?


Thanks a bunch in advance!
Letni

View 4 Replies View Related

Select From Multiple Tables

Aug 8, 2007

Basically I have 5 tables. These are...

1/ RCPCrossRef
2/ RCPPositionData

3/ RGCrossRef
4/ RGData

5/ RComments
------------------------------------------------------

RCPCrossRef and RCPPositionData are related by these keys:

RCPPositionData.UniquePositionID = RCPCrossRef.CPPositionID

RGCrossRef and RGData are related by these keys:

ON RGData.PositionID = RGCrossRef.GPositionID

-----------------------------------------------------------

RCPCrossRef and RGCrossRef are related by these keys:

ON RCPCrossRef.GMatchID = RGCrossRef.GMatchID

But RCPCrossRef may also contain a NULL value for this key meaning no relationship exists for that row.

----------------------------------------------------------------

Finally RComments is related to RCPCrossRef and RGCrossRef by these keys...

ON RComments.GPositionID = RGCrossRef.GPositionID
ON RComments.CPPositionID = RCPCrossRef.CPPositionID

But again, one of these columns in the RComments table could contain a NULL value meaning no relationship exists for that row of data.

---------------------------------------------------------------

So my aim is to display ALL DATA for each of these tables.

Tried the below but doesn't return any rows...




Code SnippetSELECT gd.Quantity, c.Comments,
gc.GPositionID, cc.CPPositionID, cd.PositionDate
FROM ReconComments AS c
INNER JOIN
RGCrossRef AS gc
INNER JOIN
RGData AS gd
ON gc.GPositionID = gd.PositionID
ON c.GPositionID = gc.GPositionID
INNER JOIN
RCPData AS cd
INNER JOIN
RCPCrossRef AS cc
ON cd.UniquePositionID = cc.CPPositionID
ON c.CPPositionID = cc.CPPositionID
WHERE gc.ForcedMatch = 'yes' AND cc.ForcedMatch = 'yes'





Thanks.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved