Showing posts with label query. Show all posts
Showing posts with label query. Show all posts

Friday, March 30, 2012

Network error when running a query

Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I receive
an error very often
"[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead (WrapperRead())
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation."
How can I fix it?Hi,
Do you have SQL Server on Windows 2003?
If you do, try removing Named Pipes from Enabled Network Libraries in Server
Network Utility.
--
Danijel Novak
"Elena" <Elena@.discussions.microsoft.com> wrote in message
news:07702D19-01BA-4A62-9F1B-CC758C1C4460@.microsoft.com...
> Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I
> receive
> an error very often
> "[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead
> (WrapperRead())
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation."
> How can I fix it?
>|||Thanks for reply, Danijel. Yes, SQL Server 2000 is running on Windows Server
2003 machine. But how will removing Named Piies influence application
performance? Do I need to stop and restart production server after
reconfiguration?
Elena
"Danijel Novak" wrote:
> Hi,
> Do you have SQL Server on Windows 2003?
> If you do, try removing Named Pipes from Enabled Network Libraries in Server
> Network Utility.
> --
> Danijel Novak
>
> "Elena" <Elena@.discussions.microsoft.com> wrote in message
> news:07702D19-01BA-4A62-9F1B-CC758C1C4460@.microsoft.com...
> > Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I
> > receive
> > an error very often
> > "[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead
> > (WrapperRead())
> > Server: Msg 11, Level 16, State 1, Line 0
> > General network error. Check your network documentation."
> > How can I fix it?
> >
>
>|||Hi,
removing Named Pipes should not influence application performance. Just keep
TCP/IP in there.
I'm not sure about restarting the service but I think you don't have to
restart SQL Server for that.
--
Danijel Novak
"Elena" <Elena@.discussions.microsoft.com> wrote in message
news:0CD3D9ED-DA33-4D7B-BDD3-C3C486158A68@.microsoft.com...
> Thanks for reply, Danijel. Yes, SQL Server 2000 is running on Windows
> Server
> 2003 machine. But how will removing Named Piies influence application
> performance? Do I need to stop and restart production server after
> reconfiguration?
> Elena
> "Danijel Novak" wrote:
>> Hi,
>> Do you have SQL Server on Windows 2003?
>> If you do, try removing Named Pipes from Enabled Network Libraries in
>> Server
>> Network Utility.
>> --
>> Danijel Novak
>>
>> "Elena" <Elena@.discussions.microsoft.com> wrote in message
>> news:07702D19-01BA-4A62-9F1B-CC758C1C4460@.microsoft.com...
>> > Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I
>> > receive
>> > an error very often
>> > "[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead
>> > (WrapperRead())
>> > Server: Msg 11, Level 16, State 1, Line 0
>> > General network error. Check your network documentation."
>> > How can I fix it?
>> >
>>

Network error when running a query

Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I receive
an error very often
"[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead (WrapperRead())
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation."
How can I fix it?
Hi,
Do you have SQL Server on Windows 2003?
If you do, try removing Named Pipes from Enabled Network Libraries in Server
Network Utility.
Danijel Novak
"Elena" <Elena@.discussions.microsoft.com> wrote in message
news:07702D19-01BA-4A62-9F1B-CC758C1C4460@.microsoft.com...
> Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I
> receive
> an error very often
> "[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead
> (WrapperRead())
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation."
> How can I fix it?
>
|||Thanks for reply, Danijel. Yes, SQL Server 2000 is running on Windows Server
2003 machine. But how will removing Named Piies influence application
performance? Do I need to stop and restart production server after
reconfiguration?
Elena
"Danijel Novak" wrote:

> Hi,
> Do you have SQL Server on Windows 2003?
> If you do, try removing Named Pipes from Enabled Network Libraries in Server
> Network Utility.
> --
> Danijel Novak
>
> "Elena" <Elena@.discussions.microsoft.com> wrote in message
> news:07702D19-01BA-4A62-9F1B-CC758C1C4460@.microsoft.com...
>
>
|||Hi,
removing Named Pipes should not influence application performance. Just keep
TCP/IP in there.
I'm not sure about restarting the service but I think you don't have to
restart SQL Server for that.
Danijel Novak
"Elena" <Elena@.discussions.microsoft.com> wrote in message
news:0CD3D9ED-DA33-4D7B-BDD3-C3C486158A68@.microsoft.com...[vbcol=seagreen]
> Thanks for reply, Danijel. Yes, SQL Server 2000 is running on Windows
> Server
> 2003 machine. But how will removing Named Piies influence application
> performance? Do I need to stop and restart production server after
> reconfiguration?
> Elena
> "Danijel Novak" wrote:

Network error when running a query

Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I receive
an error very often
"[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead (Wr
apperRead())
Server: Msg 11, Level 16, State 1, Line 0
General network error. Check your network documentation."
How can I fix it?Hi,
Do you have SQL Server on Windows 2003?
If you do, try removing Named Pipes from Enabled Network Libraries in Server
Network Utility.
Danijel Novak
"Elena" <Elena@.discussions.microsoft.com> wrote in message
news:07702D19-01BA-4A62-9F1B-CC758C1C4460@.microsoft.com...
> Running long queries (mostly DBCC commands) on SQL Server 2000 SP3 I
> receive
> an error very often
> "[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead
> (WrapperRead())
> Server: Msg 11, Level 16, State 1, Line 0
> General network error. Check your network documentation."
> How can I fix it?
>|||Thanks for reply, Danijel. Yes, SQL Server 2000 is running on Windows Server
2003 machine. But how will removing Named Piies influence application
performance? Do I need to stop and restart production server after
reconfiguration?
Elena
"Danijel Novak" wrote:

> Hi,
> Do you have SQL Server on Windows 2003?
> If you do, try removing Named Pipes from Enabled Network Libraries in Serv
er
> Network Utility.
> --
> Danijel Novak
>
> "Elena" <Elena@.discussions.microsoft.com> wrote in message
> news:07702D19-01BA-4A62-9F1B-CC758C1C4460@.microsoft.com...
>
>|||Hi,
removing Named Pipes should not influence application performance. Just keep
TCP/IP in there.
I'm not sure about restarting the service but I think you don't have to
restart SQL Server for that.
Danijel Novak
"Elena" <Elena@.discussions.microsoft.com> wrote in message
news:0CD3D9ED-DA33-4D7B-BDD3-C3C486158A68@.microsoft.com...[vbcol=seagreen]
> Thanks for reply, Danijel. Yes, SQL Server 2000 is running on Windows
> Server
> 2003 machine. But how will removing Named Piies influence application
> performance? Do I need to stop and restart production server after
> reconfiguration?
> Elena
> "Danijel Novak" wrote:
>

network error

Hi,
Running a stored procedure in query analyser returns data but when running the asp.net page which uses that stored procedure returns an exception which is:
General network error. Check your network documentation

Do you know what the problem could be please?
ThanksNetwork errors are your SQL Server is installed with the local systems account which leaves SQL Server Agent without Network permissions. The solution you have to install SQL Server with a service account. Hope this helps.

Kind regards,
Gift Peddie|||Hi,
Are you sure this is the solution?
It's just that the query works for some and not for all of the queries that are passed through the network.
Thanks|||Installing SQL Server with a service account is good practice in all but free standing developer boxes because after SQL Server Service, SQL Server Agent is the next most important service in SQL Server. Some distributed queries will fail and you cannot run Replication because the Local Systems account leaves SQL Server Agent without Network permissions. Hope this helps.

Kind regards,
Gift Peddie

Friday, March 23, 2012

Nesting a SP inside a Query

This does not work:
select * from (exec sp_lock) as ex
I want to process sp_lock in code as a table. How can I do this?
SeanSean
Create a table that will contain all columns from sp_lock stored procedure
and the perform
insert into #t exec sp_lock
select * from #t
"Sean Smith" <dremoorSPAMSUX@.msn.com> wrote in message
news:ePz9bgLUFHA.628@.tk2msftngp13.phx.gbl...
> This does not work:
> select * from (exec sp_lock) as ex
> I want to process sp_lock in code as a table. How can I do this?
> Sean
>|||Thanks but...
insert into #t exec sp_lock
gives...
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name '#t'.|||ignore than last message... I'm doing 10 things at once
"Sean Smith" <dremoorSPAMSUX@.msn.com> wrote in message
news:OD$E9WMUFHA.2540@.tk2msftngp13.phx.gbl...
> Thanks but...
> insert into #t exec sp_lock
> gives...
> Server: Msg 208, Level 16, State 1, Line 1
> Invalid object name '#t'.
>|||You have to create the temp table first. Try this:
Create Table #Locks
(
spid int
, dbid int
, objId int
, indid int
, type nvarchar(10)
, resource ntext
, mode nvarchar(2)
, status nvarchar(25)
)
Insert #Locks
Exec sp_lock
Granted, I'm using the Force in determining the data types and sizes for the
various columns.
Thomas
"Sean Smith" <dremoorSPAMSUX@.msn.com> wrote in message
news:ePz9bgLUFHA.628@.tk2msftngp13.phx.gbl...
> This does not work:
> select * from (exec sp_lock) as ex
> I want to process sp_lock in code as a table. How can I do this?
> Sean
>sql

Monday, March 19, 2012

Nested SELECT query that also returns COUNT from related table

OK heres the situation, I have a Categories table and a Products table, each Category can have one or many Products, but a product can only belong to one Category hence one-to-many relationship.

Now I want to do a SELECT query that outputs all of the Categories onto an ASP page, but also displays how many Products are in each category eg.

CatID | Name | Description | No. Products

0001 | Cars | Blah blah blah | 5

etc etc

At the moment I'm doing nesting in my application logic so that for each category that is displayed, another query is run that returns the number of products for that particular category. It works ok!

However, is there a way to write a SQL Statement that returns all the Categories AND number products from just the one SELECT statement, rather than with the method I'm using outlined above? The reason I'm asking is that I want to be able to order by the number of products for each category and my method doesn't allow me to do this.

Many thanks!Use an aggregate query:

select Category.CatID,
Category.Name,
...
count(distinct Product.ProductID) ProductCount
from Categories
left outer join Products on Categories.CategoryID = Products.CategoryID
group by Category.CatID,
Category.Name,
...
order by count(distinct Product.ProductID)|||Absolutely brilliant, it works fantastically, thank you so much!! :D

Now to try and figure out how it actually works :)|||If you use Books Online to figure out how this query works, you can consider yourself to have passed SQL 101. It incorporates the most fundamental aspects of SQL programming.

nested select

is it possible to make this query right?
SELECT name ,(select count(*) FROM NAME) FROM sysobjects
WHERE xtype='U'
I'm trying to get the list of the tables names from the current database and
for each table to get it's rows number. I dont want to use functions. I need
to do it in one query.
Regards
OfirNope, you can't have a nested SELECT where you want the table itself to be a
value from outer SELECT.
Something like this should work, but the rowcount is not 100% accurate:
SELECT o.name, i.rows
FROM sysobjects AS o
INNER JOIN
sysindexes AS i
ON o.id = i.id
WHERE o.type = 'u'
AND i.indid in (1, 0)
You could use sp_spaceused instead. See Books Online for more info. Also,
see if this helps:
http://vyaskn.tripod.com/sp_show_biggest_tables.htm
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"ofir" <ofir@.discussions.microsoft.com> wrote in message
news:FDFA7C45-49BE-4EAE-A2C6-A2C7428E0AC3@.microsoft.com...
is it possible to make this query right?
SELECT name ,(select count(*) FROM NAME) FROM sysobjects
WHERE xtype='U'
I'm trying to get the list of the tables names from the current database and
for each table to get it's rows number. I dont want to use functions. I need
to do it in one query.
Regards
Ofir|||Hi
You can also try using this
create table #rowcount (tablename varchar(128), rowcnt int)
exec sp_MSforeachtable
'insert into #rowcount select ''?'', count(*) from ?'
select * from #rowcount
drop table #rowcount
but, please note that sp_msforeachtable is an undocumented stored procedure.
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"ofir" wrote:

> is it possible to make this query right?
> SELECT name ,(select count(*) FROM NAME) FROM sysobjects
> WHERE xtype='U'
> I'm trying to get the list of the tables names from the current database a
nd
> for each table to get it's rows number. I dont want to use functions. I ne
ed
> to do it in one query.
> Regards
> Ofir|||what do u mean 'the rowcount is not 100%'
"Narayana Vyas Kondreddi" <answer_me@.hotmail.com> wrote in message
news:ucnoqMSYFHA.252@.TK2MSFTNGP12.phx.gbl...
> Nope, you can't have a nested SELECT where you want the table itself to be
> a
> value from outer SELECT.
> Something like this should work, but the rowcount is not 100% accurate:
> SELECT o.name, i.rows
> FROM sysobjects AS o
> INNER JOIN
> sysindexes AS i
> ON o.id = i.id
> WHERE o.type = 'u'
> AND i.indid in (1, 0)
>
> You could use sp_spaceused instead. See Books Online for more info. Also,
> see if this helps:
> http://vyaskn.tripod.com/sp_show_biggest_tables.htm
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "ofir" <ofir@.discussions.microsoft.com> wrote in message
> news:FDFA7C45-49BE-4EAE-A2C6-A2C7428E0AC3@.microsoft.com...
> is it possible to make this query right?
> SELECT name ,(select count(*) FROM NAME) FROM sysobjects
> WHERE xtype='U'
> I'm trying to get the list of the tables names from the current database
> and
> for each table to get it's rows number. I dont want to use functions. I
> need
> to do it in one query.
> Regards
> Ofir
>|||sysindexes maintains a rowcount, but it's not 100% accurate. Only reliable
way is to SELECT COUNT(*) from the table.
--
HTH,
Vyas, MVP (SQL Server)
SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
"ofir" <ofir@.millenium.org.il> wrote in message
news:u$O0SHTYFHA.1404@.TK2MSFTNGP09.phx.gbl...
what do u mean 'the rowcount is not 100%'
"Narayana Vyas Kondreddi" <answer_me@.hotmail.com> wrote in message
news:ucnoqMSYFHA.252@.TK2MSFTNGP12.phx.gbl...
> Nope, you can't have a nested SELECT where you want the table itself to be
> a
> value from outer SELECT.
> Something like this should work, but the rowcount is not 100% accurate:
> SELECT o.name, i.rows
> FROM sysobjects AS o
> INNER JOIN
> sysindexes AS i
> ON o.id = i.id
> WHERE o.type = 'u'
> AND i.indid in (1, 0)
>
> You could use sp_spaceused instead. See Books Online for more info. Also,
> see if this helps:
> http://vyaskn.tripod.com/sp_show_biggest_tables.htm
> --
> HTH,
> Vyas, MVP (SQL Server)
> SQL Server Articles and Code Samples @. http://vyaskn.tripod.com/
>
> "ofir" <ofir@.discussions.microsoft.com> wrote in message
> news:FDFA7C45-49BE-4EAE-A2C6-A2C7428E0AC3@.microsoft.com...
> is it possible to make this query right?
> SELECT name ,(select count(*) FROM NAME) FROM sysobjects
> WHERE xtype='U'
> I'm trying to get the list of the tables names from the current database
> and
> for each table to get it's rows number. I dont want to use functions. I
> need
> to do it in one query.
> Regards
> Ofir
>

Nested Repeater Query

Hello Everyone,

I am trying to create a query for the purpose of a nested repeater relation. The information needs to be pulled from one table. I have shortened the columns to the ones that are required.

table - Pages

ID
PageName
ParentPageID

So, take the following example:

ID 14, PageName - Service A, ParentPage ID = 6
ID 15, PageName - Service B, ParentPage ID = 6
ID 36 PageName - Client 1, ParentPage ID = 14
ID 37 PageName - Client 2, ParentPage ID = 14
ID 38 PageName - Client 3, ParentPage ID = 15
ID 39 PageName - Client 4, ParentPage ID = 15

So, I want to create a query that will get my nested repeater to display as follows:

Service A
Client 1
Client 2
Service B
Client 3
Client 4

What I have come up with so far is:

SELECT * from tbl_Pages WHERE ParentPageID IN (Select ID From tbl_Pages)

SELECT p.ParentPageID, p.PageName, p.ID FROM tbl_Pages p


The relation would be based off ParentPageID. I keep getting errors that either there is no unique value or the relation is null. What am I am missing here?

Replace

SELECT * from tbl_Pages WHERE ParentPageID IN (Select ID From tbl_Pages)

SELECT p.ParentPageID, p.PageName, p.ID FROM tbl_Pages p

with

SELECT * from tbl_Pages Parent inner join tbl_Pages Child on Parent.Id = Child.ParentPageID

Inform me if this works for u

|||

Thank you, the query worked great! I am now trying to make it work with a nested repeater however, and I am getting the following error:

System.IndexOutOfRangeException: Cannot find table 1.


I am assuming this is because this query places everything in 1 table, right? Here is my codebehind (I haven't placed the query in a stored procedure yet)

public partial class Controls_RightSideBarNavTree : BaseControl
{
protected void Page_Load(object sender, EventArgs e)
{
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["dsn1"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connString);
SqlCommand MyCommand = new SqlCommand("SELECT * from tbl_Pages Parent inner join tbl_Pages Child on Parent.Id = Child.ParentPageID", myConnection);
SqlDataAdapter ad = new SqlDataAdapter(MyCommand);
DataSet ds = new DataSet();
ad.Fill(ds);

ds.Relations.Add(new DataRelation("NavigationRelation", ds.Tables[0].Columns["ParentPageID"], ds.Tables[1].Columns["ParentPageID"]));
Repeater1.DataSource = ds.Tables[0];
Repeater1.DataBind();
}
}

protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
DataRowView drv = e.Item.DataItem as DataRowView;
Repeater childRepeater = e.Item.FindControl("childRepeater") as Repeater;
childRepeater.DataSource = drv.CreateChildView("NavigationRelation");
childRepeater.DataBind();
}
}

|||

try this

u have to add next to the repeater in an item template a label with the Eval("Id"), and lets give it an id="label1"

protected void Page_Load(object sender, EventArgs e)
{
string connString = System.Configuration.ConfigurationManager.ConnectionStrings["dsn1"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connString);
SqlCommand MyCommand = new SqlCommand("SELECT * from tbl_Pages Parent inner join tbl_Pages Child on Parent.Id = Child.ParentPageID", myConnection);
SqlDataAdapter ad = new SqlDataAdapter(MyCommand);
DataSet ds = new DataSet();
ad.Fill(ds);

Repeater1.DataSource = ds.Tables[0];
Repeater1.DataBind();
}
}

protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{

string connString = System.Configuration.ConfigurationManager.ConnectionStrings["dsn1"].ConnectionString;
SqlConnection myConnection = new SqlConnection(connString);
SqlCommand MyCommand = new SqlCommand("SELECT * from tbl_Pages Parent inner join tbl_Pages Child on Parent.Id = Child.ParentPageID where Parent.Id = @.ID",myConnection);
Label lbl = (Label)e.Item.FindControl("Label1");

MyCommand.Parameters.Add("@.Id",lbl.Text);
SqlDataAdapter ad = new SqlDataAdapter(MyCommand);
DataSet ds = new DataSet();
ad.Fill(ds);
Repeater childRepeater = e.Item.FindControl("childRepeater") as Repeater;
childRepeater.DataSource = ds;
childRepeater.DataBind();
}
}

Inform me if this works for u.

|||

Thank you very much for your help. I see that you are from Lebanon. I am originally from Damascus :)

Anyway, I had to make a change to the first query in order to get the correct results for the first query...
SELECT * from tbl_Pages WHERE ParentPageID = @.ID (@.ID is taken from a class BasicPageInfo.ID)

However, when using the 2nd query for the childrepeater, I get the following error:
System.NullReferenceException: Object reference not set to an instance of an object. on Line 47 childRepeater.DataSource = ds;

When I run the query in SQL Server Management Studio I get the correct result when I pass, for example, 32 for the @.ID.

This error was happening when i used the first query the way you had indicated as well. Seems to me, that for some reason, the dataset is not being populated correctly.

This is what I intend on doing. Before trying to use a nested repeater, these were my functions to create a navigation menu. This worked just fine, but I couldn't figure out how to insert a nested repeater into the below code (I took this over from another developer).

public partial class Controls_RightSideBarNavTree : BaseControl
{
protected void Page_Load(object sender, EventArgs e)
{
PagesDB sdb1 = new PagesDB();
BasicPageData[] dataArray1 = null;
int num1 = -1;

if (base.BasicPageInfo != null)
{
dataArray1 = sdb1.Page_GetAllWithParentID(base.BasicPageInfo.ID);
num1 = base.BasicPageInfo.ID;
if (dataArray1.Length == 0)
{
dataArray1 = sdb1.Page_GetAllWithParentID(base.BasicPageInfo.ParentPageID);
num1 = base.BasicPageInfo.ParentPageID;
}

/* Checks to see if page is a content page. If so, applied Header Text */
if (num1 > 0)
{
BasicPageData data1 = sdb1.Page_GetItemByID(num1);
this.lblHeader.Text = data1.PageName;
this.Repeater1.DataSource = dataArray1;
this.Repeater1.DataBind();
}
else
{
this.lblHeader.Text = "";
}
}

}

protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
BasicPageData data1 = (BasicPageData)e.Item.DataItem;
HyperLink link1 = (HyperLink)e.Item.FindControl("hypItem");
HtmlGenericControl control1 = (HtmlGenericControl)e.Item.FindControl("liItem");
if (null == data1) return;
link1.Text = data1.PageName;
link1.NavigateUrl = GlobalData.TRCBaseURL + "content/default.aspx?" + BaseControl.PAGE_GUID + "=" + data1.GUID.ToString() + "&" + BaseControl.TOOLBARPAGE_GUID + "=" + base.ToolbarPageGUID.ToString();
if (base.PageGUID.Equals(data1.GUID))
{
control1.Attributes.Add("class", "subOn");
}
}
}

}

|||

Hi adarwich,

From the context, I didn't see the control childRepeater has been initialized. Please check if childRepeater is a valid control on the page and it has a valid reference to an object.

Nested Query Troubles...

Hi All,

Can anybody please tell me if a query such as this (Valid in MS Access)
can work in SQL Server:

SELECT Description, Sum(Total) FROM (
SELECT Description, Total FROM Table_A
UNION ALL
SELECT Description, Total FROM Table_B
UNION ALL
SELECT Description, Total FROM Table_C
)
GROUP BY Description


The group of unions work by themselves, but when I try to nest an outer query to do some a Summation(), I have syntax errors.

Any insight would be greatly appreciated. Thank you.You must supply an alias for your subquery:
SELECT Description,
Sum(Total)
FROM (SELECT Description,
Total
FROM Table_A
UNION ALL
SELECT Description,
Total
FROM Table_B
UNION ALL
SELECT Description,
Total
FROM Table_C) AS SUBQUERY
GROUP BY Description|||Thanks BlindMan, u da man.

:)

Nested Query Problem

I am writing a stored procedure that has to insert several rows from one table to another. The problem is that the table into which the rows will be inserted, has more columns than the table that the rows come from. When the stored procedure is called, the extra columns in each new row is supposed to be populated by the stored procedure's arguments. Example:

TableA:
Columns: ID, Group, Name, Email, NewletterSubscriber

TableB:
Columns: ID, Name, Email

The arguments provided are Group, and NewsletterSubscriber.

I need to insert into Table A all records from Table B where ID > 1000 and I need to insert the Group and NewsLetterSubscriber arguments at the same time because these columns do not allow nulls.

I think it might be something like

insert into TableA (ID, Group, Name, Email, NewletterSubscriber)
values (
select * from TableB where ID > 1000)

But how do I insert the stored procedure arguments into the correct columns of the rows?

Your insert statement should be something like

insert into TableA(group, newsletterSubscriber)
values (@.arg_group, @.arg_newsletterSubscriber)

|||

As per your example:

You can do the following :

insert TableA (ID, Group, Name, Email, NewletterSubscriber)

select ID,@.Group,Name,Email,@.NewsletterSubscriber from TableB where ID > 1000

Here @.Group and @.NewsletterSubscriber are a arguments from a Stored procedure.

Thanks

Naras.

|||

I think the procedure definition you want is:

Code Snippet

CREATE PROCEDURE TransRecords_AtoB

@.DefGroup AS int,

@.DefNewsLetterSub AS bit

AS

BEGIN

-- Do you need to clear existing records if so uncomment statement below

-- DELETE FROM TableA

-- WHERE [ID] IN (

-- SELECT ID

-- FROM TableB

-- WHERE (ID > 1000)

-- )

-- Insert the required rows

INSERT INTO TableA ([ID], [Group], [Name],

[Email], [NewsLetterSubscriber])

SELECT [ID], @.DefGroup, [Name], [Email], @.DefNewsLetterSub

FROM TableB

WHERE ([ID] > 1000)

END

If you need to remove records already existing for IDs in TableB then use the commented out delete. Change the types of the arguments to match your fields.

I would recomment that you consider changing some of your column names. It is a bad idea to use identifiers that are reserved words (or might become ones). Name and Group fall into that camp and ID is also suspect. These have to be delimited as shown (and this can cause problem with autogenerated SQL in some tools). Use RecID, RecName, RecGroup etc. or something more descriptive.

Nested Query for newbie?

Hi
thanks for reading
I have 2 tables. The first has employee information and
the second has
payroll information. I need to find out people who are not
in the
payroll but in the employee table.
Since the payroll has multiple instances i have to filter
it and find
out for each payroll.
I don't think i have explained it very well so here is the
data set.
hope someone can help me with this.
Thanks in advance
prit
Tbl Employee
PlanIDSSN
1001111111111
1001222222222
1001333333333
TblPayrolldetail
IDNumPlanID SSN
11001111111111
11001222222222
21001222222222
21001333333333
Required RESULT required(Missing employees for each pay
period)
IDNumSSN
1333333333
2111111111
If you have a table with all the IDNum values (IDNum represents a pay
period?), use it, or if not,
(select Distinct IDNum from TblPayrolldetail) IDs
where I have
IDs
select IDs.IDNum, [Tbl Employee] SSN
from IDs, [Tbl Employee]
where not exists (
select * from TblPayrolldetail D
where D.IDNum = IDs.IDNum
and D.SSN = [TblEmployee].SSN
)
Steve Kass
Drew University
PM wrote:

>Hi
>thanks for reading
>I have 2 tables. The first has employee information and
>the second has
>payroll information. I need to find out people who are not
>in the
>payroll but in the employee table.
>Since the payroll has multiple instances i have to filter
>it and find
>out for each payroll.
>I don't think i have explained it very well so here is the
>data set.
>hope someone can help me with this.
>Thanks in advance
>prit
>
>Tbl Employee
>PlanIDSSN
>1001111111111
>1001222222222
>1001333333333
>TblPayrolldetail
>IDNumPlanID SSN
>11001111111111
>11001222222222
>21001222222222
>21001333333333
>Required RESULT required(Missing employees for each pay
>period)
>IDNumSSN
>1333333333
>2111111111
>
>

Nested Query (Urgent)

Folks

I have two queries

Select Account_Id , Branch_Cd from Accounts

SELECT SUM (dbo.HOLDING.Shares_Par_Value_Qty * dbo.ASSET.Current_Prc) AS MarketValue
FROM dbo.HOLDING INNER JOIN
dbo.ASSET ON dbo.HOLDING.Property_Num = dbo.ASSET.Property_Num
Group by dbo.HOLDING.Account_ID

Account_ID is the same in both the queries ie in both the tables
Holding and Account.

I need the output like this

Select Account_Id, Branch_Cd, MarketValue from ---

But MarketValue should be calculated exactly in the above method.
How do I combine these two queries. I need it asap.
Help me out.

ThanksCheck my reply to your SUM post. If it isn't clear from that then get back to me.

Ursus|||How about:

SELECT A.Account_Id , A.Branch_Cd, B.MarketValue
FROM Accounts AS A
INNER JOIN
( SELECT SUM (dbo.HOLDING.Shares_Par_Value_Qty * dbo.ASSET.Current_Prc) AS MarketValue
FROM dbo.HOLDING
INNER JOIN dbo.ASSET
ON dbo.HOLDING.Property_Num = dbo.ASSET.Property_Num
GROUP BY dbo.HOLDING.Account_ID ) AS B
ON A.Account_ID = B.Account_ID

Nested Query

Hi All,

I am stuck to a senario in which i need the help of u all.

well the present senaio is i have two table xx and yy.

the table conatins data as below:

table xx

EmployeeID Departments

10014 A

10015 A

10002 A

10013 B

10019 B

10056 B

table yy

Empoyee ID ActuaDate Start time EndTime

10014 03/30/2007 0600 1445

10015 03/30/2007 0600 1445

10002 03/30/2007 0600 1445

10013 03/31/2007 1130 1300

10019 03/31/2007 0300 1300

10056 03/31/2007 0300 1100

--

conditions :

Actdate ='03/30/2007' and starttime>='600'

or actdate ='03/31/2007' and starttime<='0300' -for pick

Result should be as:

Department EmployeeCount Pick Drop

A 3 3 3

B 3 3 3

please help me in solving the problem.

Regards

sufian

Your requirements are a bit 'unclear'. Perhaps this is in the right direction:

Code Snippet


SET NOCOUNT ON


DECLARE @.xx table
( EmployeeID int,
Department char(1)
)


INSERT INTO @.xx VALUES ( 10014, 'A' )
INSERT INTO @.xx VALUES ( 10015, 'A' )
INSERT INTO @.xx VALUES ( 10002, 'A' )
INSERT INTO @.xx VALUES ( 10013, 'B' )
INSERT INTO @.xx VALUES ( 10019, 'B' )
INSERT INTO @.xx VALUES ( 10056, 'B' )


DECLARE @.yy table
( EmployeeID int,
ActuaDate datetime,
StartTime int,
EndTime int
)


INSERT INTO @.yy VALUES ( 10014, '03/30/2007', 0600, 1445 )
INSERT INTO @.yy VALUES ( 10015, '03/30/2007', 0600, 1445 )
INSERT INTO @.yy VALUES ( 10002, '03/30/2007', 0600, 1445 )
INSERT INTO @.yy VALUES ( 10013, '03/31/2007', 1130, 1300 )
INSERT INTO @.yy VALUES ( 10019, '03/31/2007', 0300, 1300 )
INSERT INTO @.yy VALUES ( 10056, '03/31/2007', 0300, 1100 )
INSERT INTO @.yy VALUES ( 10013, '03/31/2007', NULL, NULL )
INSERT INTO @.yy VALUES ( 10056, '03/31/2007', 0300, NULL )


SELECT
x.Department,
EmployeeCount = count( DISTINCT y.EmployeeID ),
Picked = count( y.StartTime ),
Dropped = count( y.EndTime )
FROM @.XX x
JOIN @.YY y
ON x.EmployeeID = y.EmployeeID
GROUP BY x.Department

Department EmployeeCount Picked Dropped
- - -- --
A 3 3 3
B 3 4 3

|||

While I can't completely follow your requirements, I think this will give you the idea for what you want. The idea is to do a select with a group by and manufacture values using SUM

select department, count(distinct xx.employeeId) as EmployeeCount,
sum(case when actuadate ='03/31/2007' and starttime<='0300' then 1 else 0 end) as Pick
from xx
join yy
on xx.employeeId = yy.employeeId
group by department

The full code follows, and if you could provide this kind of structure (and change mine if it is wrong) it is a lot easier. Plus, if your results are what you expected to receive, it seems wrong. If it is just a basice feel for the results, I understand.

I would also consider making the start and end values a datetime. Use a constraint to make sure they are in the same day perhaps, but it will be easier to work with with date and time in the same column.

Code Snippet

create table xx
(
EmployeeId int primary key,
Department char(1)
)
insert into xx
select 10014,'A'
union all
select 10015,'A'
union all
select 10002,'A'
union all
select 10013,'B'
union all
select 10019,'B'
union all
select 10056,'B'

create table yy
(
employeeId int,
actuaDate datetime,
startTime int,
endTime int
)
insert into yy
select 10014,'03/30/2007',0600,1445
union all
select 10015,'03/30/2007',0600,1445
union all
select 10002,'03/30/2007',0600,1445
union all
select 10013,'03/31/2007',1130,1300
union all
select 10019,'03/31/2007',0300,1300
union all
select 10056,'03/31/2007',0300,1100
go


select department, count(distinct xx.employeeId) as EmployeeCount,
sum(case when actuadate ='03/31/2007' and starttime<='0300' then 1 else 0 end) as Pick
from xx
join yy
on xx.employeeId = yy.employeeId
group by department

Nested query

Hey guys,
I have this query i can't seem to get to work just write. Can anyone
help me out here?
SELECT Table1.*
FROM Table1 INNER JOIN (SELECT * FROM Table2)
ON (Table1.ProvID = Table2.ProvID) AND
(Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
-Scott
When you use a query as a dynamic table like this, you have to provide an
alias for it:
SELECT Table1.*
FROM Table1
INNER JOIN (SELECT * FROM Table2) As Table2 ON (Table1.ProvID =
Table2.ProvID) AND (Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
However, I suggest just doing a straight inner join on the tables:
SELECT Table1.*
FROM Table1
INNER JOIN Table2 ON Table1.ProvID = Table2.ProvID AND Table1.VerifDate =
Table2.VerifDate
WHERE Table1.Type Like 'A%'
"Scott Elgram" wrote:

> Hey guys,
> I have this query i can't seem to get to work just write. Can anyone
> help me out here?
> SELECT Table1.*
> FROM Table1 INNER JOIN (SELECT * FROM Table2)
> ON (Table1.ProvID = Table2.ProvID) AND
> (Table1.VerifDate = Table2.VerifDate)
> WHERE Table1.Type Like 'A%'
> --
> -Scott
>
>

Nested query

Hi, I'm just starting out with SQL. I'm wondering why this nested query
doesn't work. I'm sure it's something simple but I'm not sure what. Hope
somebody can shed some light.
Thanks in advance
Ant
SELECT myDate,
SUM(deposit)
FROM
(
SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
[myDate],
deposit
FROM loan_tbl
)
GROUP BY myDateGot it, I neglected to give the nested query an alias. Woops. Thanks anyway.
"Ant" wrote:

> Hi, I'm just starting out with SQL. I'm wondering why this nested query
> doesn't work. I'm sure it's something simple but I'm not sure what. Hope
> somebody can shed some light.
> Thanks in advance
> Ant
>
> SELECT myDate,
> SUM(deposit)
> FROM
> (
> SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
> [myDate],
> deposit
> FROM loan_tbl
> )
> GROUP BY myDate|||Simply give an alias to the sub query
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"Ant" <Ant@.discussions.microsoft.com> wrote in message
news:6433B30C-3144-4277-A495-C38D2F2B22F2@.microsoft.com...
> Hi, I'm just starting out with SQL. I'm wondering why this nested query
> doesn't work. I'm sure it's something simple but I'm not sure what. Hope
> somebody can shed some light.
> Thanks in advance
> Ant
>
> SELECT myDate,
> SUM(deposit)
> FROM
> (
> SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
> [myDate],
> deposit
> FROM loan_tbl
> )
> GROUP BY myDate|||This should be treated as a derived table:
SELECT myDate, SUM(deposit)
FROM (
SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as
datetime) as [myDate], deposit
FROM loan_tbl
) AS DerivedTable
GROUP BY myDate
best Regards,
Chandra
http://chanduas.blogspot.com/
http://groups.msn.com/SQLResource/
---
"Ant" wrote:

> Hi, I'm just starting out with SQL. I'm wondering why this nested query
> doesn't work. I'm sure it's something simple but I'm not sure what. Hope
> somebody can shed some light.
> Thanks in advance
> Ant
>
> SELECT myDate,
> SUM(deposit)
> FROM
> (
> SELECT CAST(DATENAME(MONTH,date)+ '' + DATENAME(YEAR,date)as datetime) as
> [myDate],
> deposit
> FROM loan_tbl
> )
> GROUP BY myDate

Nested query

Hey guys,
I have this query i can't seem to get to work just write. Can anyone
help me out here?
SELECT Table1.*
FROM Table1 INNER JOIN (SELECT * FROM Table2)
ON (Table1.ProvID = Table2.ProvID) AND
(Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
-ScottWhen you use a query as a dynamic table like this, you have to provide an
alias for it:
SELECT Table1.*
FROM Table1
INNER JOIN (SELECT * FROM Table2) As Table2 ON (Table1.ProvID =
Table2.ProvID) AND (Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
However, I suggest just doing a straight inner join on the tables:
SELECT Table1.*
FROM Table1
INNER JOIN Table2 ON Table1.ProvID = Table2.ProvID AND Table1.VerifDate =
Table2.VerifDate
WHERE Table1.Type Like 'A%'
"Scott Elgram" wrote:

> Hey guys,
> I have this query i can't seem to get to work just write. Can anyone
> help me out here?
> SELECT Table1.*
> FROM Table1 INNER JOIN (SELECT * FROM Table2)
> ON (Table1.ProvID = Table2.ProvID) AND
> (Table1.VerifDate = Table2.VerifDate)
> WHERE Table1.Type Like 'A%'
> --
> -Scott
>
>

Nested query

Hey guys,
I have this query i can't seem to get to work just write. Can anyone
help me out here?
SELECT Table1.*
FROM Table1 INNER JOIN (SELECT * FROM Table2)
ON (Table1.ProvID = Table2.ProvID) AND
(Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
--
-ScottWhen you use a query as a dynamic table like this, you have to provide an
alias for it:
SELECT Table1.*
FROM Table1
INNER JOIN (SELECT * FROM Table2) As Table2 ON (Table1.ProvID =Table2.ProvID) AND (Table1.VerifDate = Table2.VerifDate)
WHERE Table1.Type Like 'A%'
However, I suggest just doing a straight inner join on the tables:
SELECT Table1.*
FROM Table1
INNER JOIN Table2 ON Table1.ProvID = Table2.ProvID AND Table1.VerifDate =Table2.VerifDate
WHERE Table1.Type Like 'A%'
"Scott Elgram" wrote:
> Hey guys,
> I have this query i can't seem to get to work just write. Can anyone
> help me out here?
> SELECT Table1.*
> FROM Table1 INNER JOIN (SELECT * FROM Table2)
> ON (Table1.ProvID = Table2.ProvID) AND
> (Table1.VerifDate = Table2.VerifDate)
> WHERE Table1.Type Like 'A%'
> --
> -Scott
>
>

nested queries

i got a question of how to use a result you achieve from a query in table
form and use the result to find other stuff form the other tables
for example
SELECT Omim_No
FROM av
WHERE Description LIKE '%LIVER%'
ORDER BY Omim_No ASC
SELECT Omim_No
FROM cs
WHERE CS_Description LIKE '%LIVER%'
OR CS_DATA LIKE '%LIVER%'
ORDER BY Omim_No ASC
SELECT Omim_No
FROM ti
WHERE Omim_Titles LIKE '%LIVER%'
ORDER BY Omim_No ASC
SELECT Omim_No
FROM ti_alt_title
WHERE Omim_Alt_Titles LIKE '%LIVER%'
ORDER BY Omim_No ASC
SELECT Omim_No
FROM tx
WHERE Omim_Text LIKE '%LIVER%'
SELECT subsnp_id,pop_id,allele_id
FROM AlleleFreqBySsPop
WHERE source LIKE '%LIVER%'
Instead of seraching for the word liver in the last table i would like to
search from the result i gotten from the first five table is that possible?Store the results from the first few queries in a temporary table. A slight
modification would be needed:
create table #<temp table name>
(
Omim_No <datatype>
,TextValue ntext --?
)
insert #<temp table name>
(
Omim_No
,TextValue
)
SELECT Omim_No as Omim_No
,Description as TextValue
FROM av
WHERE Description LIKE '%LIVER%'
union all
SELECT Omim_No
,CS_Description
FROM cs
WHERE CS_Description LIKE '%LIVER%'
OR CS_DATA LIKE '%LIVER%'
union all
SELECT Omim_No
,Omim_Titles
FROM ti
WHERE Omim_Titles LIKE '%LIVER%'
union all
SELECT Omim_No
,Omim_Alt_Titles
FROM ti_alt_title
WHERE Omim_Alt_Titles LIKE '%LIVER%'
union all
SELECT Omim_No
,Omim_Text
FROM tx
WHERE Omim_Text LIKE '%LIVER%'
Also consider using full-text search, it will certainly perform batter that
the LIKE operator.
ML
http://milambda.blogspot.com/|||i have a data base to search from i search the data column omim no and i
have to link to the other table in th esame database through the omim no i
gotten through some of the other tables.
"ML" wrote:

> Store the results from the first few queries in a temporary table. A sligh
t
> modification would be needed:
> create table #<temp table name>
> (
> Omim_No <datatype>
> ,TextValue ntext --?
> )
> insert #<temp table name>
> (
> Omim_No
> ,TextValue
> )
> SELECT Omim_No as Omim_No
> ,Description as TextValue
> FROM av
> WHERE Description LIKE '%LIVER%'
> union all
> SELECT Omim_No
> ,CS_Description
> FROM cs
> WHERE CS_Description LIKE '%LIVER%'
> OR CS_DATA LIKE '%LIVER%'
> union all
> SELECT Omim_No
> ,Omim_Titles
> FROM ti
> WHERE Omim_Titles LIKE '%LIVER%'
> union all
> SELECT Omim_No
> ,Omim_Alt_Titles
> FROM ti_alt_title
> WHERE Omim_Alt_Titles LIKE '%LIVER%'
> union all
> SELECT Omim_No
> ,Omim_Text
> FROM tx
> WHERE Omim_Text LIKE '%LIVER%'
>
> Also consider using full-text search, it will certainly perform batter tha
t
> the LIKE operator.
> ML
> --
> http://milambda.blogspot.com/|||The temporary table in my previous post stores the results of your queries
and can be joined on the Omim_No column to any other table where this column
is used.
What is the problem?
ML
http://milambda.blogspot.com/

Nested or Subquery help

i am new to SQL Server DB.
i have a typical query problem.
master table contains Data in following format
id stype sid svalue
1 status 1 approved
2 status 2 pending
3 request 1 draft
4 request 2 waiting
etc

in my query i need to substitute the svalue in place of sid
e.g.
select requestid ,bstatus, brequest from request ;
should give
----------
R1122 approved draft
----------
instead of
R1122 1 1
*****************
link field is column name (quite unusual )
like for status column , it is bstatus column name and it is stored in master table as status .

i need to do the following in 1 query only.
kindly suggest some nested query to do the same
kindly help
Smitaselect requestid
, s.svalue as statusvalue
, r.svalue as requestvalue
from request
inner
join master as s
on bstatus = s.sid
and s.stype = 'status'
inner
join master as r
on bstatus = r.sid
and r.stype = 'request'

nested loops join

Hi,
I have a select statement that gets data from only one table.
When I write OPTION(LOOP JOIN) after this query and run it, the
execution time is 2-3 times faster than without OPTION(LOOP JOIN).
If I use OPTION(FAST 1) the execution time is as fast as with OPTION(LOOP
JOIN)
Does anyone know why its faster with nested loops join even though I don't
join any tables?
Thanks!
//MalinDid you look at the actual execution plan to see what it is doing in both
cases?
Andrew J. Kelly SQL MVP
"Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
news:uwxC2gaRFHA.1500@.TK2MSFTNGP09.phx.gbl...
> Hi,
> I have a select statement that gets data from only one table.
> When I write OPTION(LOOP JOIN) after this query and run it, the
> execution time is 2-3 times faster than without OPTION(LOOP JOIN).
> If I use OPTION(FAST 1) the execution time is as fast as with OPTION(LOOP
> JOIN)
> Does anyone know why its faster with nested loops join even though I don't
> join any tables?
> Thanks!
> //Malin
>|||The graphical execution plans are identical. (select <-- Clustered index
s)
If I have set showplan_text on there is a difference.
select col1, col2, col3
from table1
where col1=1234
option(loop join)
|--Clustered Index S(OBJECT:([DB].[dbo].[table1].[PK_tIndex]),
SEEK:([table1].[col1]=Convert([@.1])) ORDERED FORWARD)
select col1, col2, col3
from table1
where col1=1234
|--Clustered Index S(OBJECT:([DB].[dbo].[table1].[PK_tIndex]),
SEEK:([table1].[col1]=1234) ORDERED FORWARD)
Does "Convert([@.1])" have something to do with the execution time of the
query?
Thanks for helping.
// Malin
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:eSqTusaRFHA.2604@.TK2MSFTNGP10.phx.gbl...
> Did you look at the actual execution plan to see what it is doing in both
> cases?
> --
> Andrew J. Kelly SQL MVP
>
> "Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
> news:uwxC2gaRFHA.1500@.TK2MSFTNGP09.phx.gbl...
>|||for instance, ...perhaps you have a couple of search arguments ANDed and SQL
Server can join these
by two indexes (aka index intersection) and this is the join which is influe
nced by your hint.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:eSqTusaRFHA.2604@.TK2MSFTNGP10.phx.gbl...
> Did you look at the actual execution plan to see what it is doing in both
cases?
> --
> Andrew J. Kelly SQL MVP
>
> "Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
> news:uwxC2gaRFHA.1500@.TK2MSFTNGP09.phx.gbl...
>|||Hej :-),
I only have one argument in the where statement.
My query looks like "select col1, col2, col3 from table1 where col1=1234"
(as you probably already have seen in my previous message)
That's why I wonder where the "join" is?
// Malin
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:%23LGPO7aRFHA.3928@.TK2MSFTNGP09.phx.gbl...
> for instance, ...perhaps you have a couple of search arguments ANDed and
> SQL Server can join these by two indexes (aka index intersection) and this
> is the join which is influenced by your hint.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:eSqTusaRFHA.2604@.TK2MSFTNGP10.phx.gbl...
>|||Hej. :-)
Strange... Did you look at the execution plan?
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
news:%23pJpeDbRFHA.3444@.tk2msftngp13.phx.gbl...
> Hej :-),
> I only have one argument in the where statement.
> My query looks like "select col1, col2, col3 from table1 where col1=1234"
(as you probably
> already have seen in my previous message)
> That's why I wonder where the "join" is?
> // Malin
>
> "Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote i
n message
> news:%23LGPO7aRFHA.3928@.TK2MSFTNGP09.phx.gbl...
>|||The graphical execution plans are identical. (select <-- Clustered index
s)
If I have set showplan_text on there is a difference.
select col1, col2, col3
from table1
where col1=1234
option(loop join)
|--Clustered Index S(OBJECT:([DB].[dbo].[table1].[PK_tIndex]),
SEEK:([table1].[col1]=Convert([@.1])) ORDERED FORWARD)
select col1, col2, col3
from table1
where col1=1234
|--Clustered Index S(OBJECT:([DB].[dbo].[table1].[PK_tIndex]),
SEEK:([table1].[col1]=1234) ORDERED FORWARD)
Does "Convert([@.1])" have something to do with the execution time of the
query?
Anything more I can do to find out what this can depend on?
// Malin
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:eVHTpHbRFHA.3076@.tk2msftngp13.phx.gbl...
> Hej. :-)
> Strange... Did you look at the execution plan?
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
> news:%23pJpeDbRFHA.3444@.tk2msftngp13.phx.gbl...
>|||In this example you have the value for Col1 as an integer. In the real
table is the datatype for Col1 an Integer?
Andrew J. Kelly SQL MVP
"Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
news:e0XLO5aRFHA.1172@.TK2MSFTNGP12.phx.gbl...
> The graphical execution plans are identical. (select <-- Clustered index
> s)
> If I have set showplan_text on there is a difference.
> select col1, col2, col3
> from table1
> where col1=1234
> option(loop join)
> |--Clustered Index S(OBJECT:([DB].[dbo].[table1].[PK_tIndex]),
> SEEK:([table1].[col1]=Convert([@.1])) ORDERED FORWARD)
>
> select col1, col2, col3
> from table1
> where col1=1234
> |--Clustered Index S(OBJECT:([DB].[dbo].[table1].[PK_tIndex]),
> SEEK:([table1].[col1]=1234) ORDERED FORWARD)
> Does "Convert([@.1])" have something to do with the execution time of the
> query?
> Thanks for helping.
> // Malin
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:eSqTusaRFHA.2604@.TK2MSFTNGP10.phx.gbl...
>|||yes "col1" is an integer in the real table, the query looks exactly as I
have written except the names :-)
//Malin
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:%23LZ9yTbRFHA.904@.tk2msftngp13.phx.gbl...
> In this example you have the value for Col1 as an integer. In the real
> table is the datatype for Col1 an Integer?
> --
> Andrew J. Kelly SQL MVP
>
> "Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
> news:e0XLO5aRFHA.1172@.TK2MSFTNGP12.phx.gbl...
>|||I will post to the internal group and see if anyone has seen this before.
Andrew J. Kelly SQL MVP
"Malin Davidsson" <malin.davidsson(at)aus.teleca.se> wrote in message
news:uvQUHabRFHA.3076@.TK2MSFTNGP14.phx.gbl...
> yes "col1" is an integer in the real table, the query looks exactly as I
> have written except the names :-)
> //Malin
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:%23LZ9yTbRFHA.904@.tk2msftngp13.phx.gbl...
>