Showing posts with label execute. Show all posts
Showing posts with label execute. Show all posts

Friday, March 30, 2012

Receiving error when trying to use try..catch block

I am using SQL Server 2005 and am trying to execute the following statements:

BEGIN TRY SELECT 1/0 END TRY BEGIN CATCH SELECT 'Error Caught' END CATCH I am getting the following errors:

Msg 170, Level 15, State 1, Line 1

Line 1: Incorrect syntax near 'TRY'.

Msg 156, Level 15, State 1, Line 3

Incorrect syntax near the keyword 'END'.

This code should work, can anyone tell me why it it not working?

Thanks in advace.

Hmmm, works fine here.


Is there something else you have coded in the same script?

Are you using SSMS?

|||Sorry, my mistake. I was using our SQL Server 2005 Management Studio, but had accidentally connected to the SQL Server 2000 box to test with. Thanks.|||Been there, done that Smile

Wednesday, March 28, 2012

Receive "Acquiring a connection requires a valid Task name" when

Hi All,
I'm creating "DTSExecuteSQLTask" Task in DDQ ActiveX script code. Then
I'm trying to execute it from within this code with command:
oCustomerTask.execute oPkg, Nothing, Nothing,
DTSTaskExecResult_Success
but I receive error message:
"Acquiring a connection requires a valid Task name".
What's the matter?
Following is my activx script code
'***************************************
*******************************
' Visual Basic ActiveX Script
'***************************************
*********************************
Function Main()
Dim oPkg, startDate, oTask, oConnection, oCustomerTask
Dim oResult
set oPkg = DTSGlobalVariables.parent
startDate = DTSGlobalVariables("startDate")
Set oConnection = oPkg.Connections("db_conn2")
Set oTask = oPkg.tasks.new("DTSExecuteSQLTask")
oTask.Name = "DTSTask_DTSExecuteSQLTask_1"
Set oCustomerTask = oTask.CustomTask
oCustomerTask.Name = "DTSTask_DTSExecuteSQLTask_1"
oCustomerTask.description = "test task"
oCustomerTask.ConnectionID=oConnection.id
oCustomerTask.CommandTimeout=0
oCustomerTask.OutputAsRecordset = False
oCustomerTask.SQLStatement = "delete from tmp_table"
oCustomerTask.execute oPkg, Nothing, Nothing,
DTSTaskExecResult_Success
Set oCustomerTask = Nothing
set oTask=Nothing
Set oConnection=Nothing
set oPkg=nothing
Main = DTSTaskExecResult_Success
End Function
What's wrong?
Thanks in advance.I have found the resolution, after you create the task, you need
create a step object whcih will refers this new created task, you also
need add the task to current package. And then execute the step, you
can get the result. After the step complets, you need to remove the
task from package.
This solution works for me, but I do not know this is the best
solution or not. If anybody has more better solution, please post it.
Thanks a lot.
Following is the code which can run on my SQL Server 2000 Enterprise
Edition
'***************************************
*******************************
' Visual Basic ActiveX Script
'***************************************
*********************************
Function Main()
Dim oPkg, startDate, oTask, oConnection, oCustomerTask
Dim oResult
set oPkg = DTSGlobalVariables.parent
startDate = DTSGlobalVariables("startDate")
Set oConnection = oPkg.Connections("db_conn2")
'create task itself
Set oTask = oPkg.tasks.new("DTSExecuteSQLTask")
oTask.Name = "DTSTask_DTSExecuteSQLTask_1"
Set oCustomerTask = oTask.CustomTask
oCustomerTask.Name = "DTSTask_DTSExecuteSQLTask_1"
oCustomerTask.description = "test task"
oCustomerTask.ConnectionID=oConnection.id
oCustomerTask.CommandTimeout=0
oCustomerTask.OutputAsRecordset = False
oCustomerTask.SQLStatement = "select * from test_table"
oPkg.tasks.add oTask
'associate step with a task
Dim oStep
Set oStep = oPkg.Steps.New
oStep.Name = "DTSStep_DTSExecuteSQLTask_1"
oStep.Description = "Execute SQL Task: undefined"
oStep.ExecutionStatus = 1
oStep.TaskName = "DTSTask_DTSExecuteSQLTask_1"
oStep.CommitSuccess = False
oStep.RollbackFailure = False
oStep.ScriptLanguage = "VBScript"
oStep.AddGlobalVariables = True
oStep.RelativePriority = 3
oStep.CloseConnection = False
oStep.ExecuteInMainThread = False
oStep.IsPackageDSORowset = False
oStep.JoinTransactionIfPresent = False
oStep.DisableStep = False
oStep.FailPackageOnError = False
'run step
oStep.execute
'remove the added customer task
Dim index
For index=1 To oPkg.tasks.count
If (oPkg.tasks.item(index).name = "DTSTask_DTSExecuteSQLTask_1")
Then
oPkg.tasks.remove index
Exit For
End If
Next
Set oStep = Nothing
Set oCustomerTask = Nothing
set oTask=Nothing
Set oConnection=Nothing
set oPkg=nothing
Main = DTSTaskExecResult_Success
End Function

Monday, March 26, 2012

Receive "Acquiring a connection requires a valid Task name" when

Hi All,
I'm creating "DTSExecuteSQLTask" Task in DDQ ActiveX script code. Then
I'm trying to execute it from within this code with command:
oCustomerTask.execute oPkg, Nothing, Nothing,
DTSTaskExecResult_Success
but I receive error message:
"Acquiring a connection requires a valid Task name".
What's the matter?
Following is my activx script code
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
Dim oPkg, startDate, oTask, oConnection, oCustomerTask
Dim oResult
set oPkg = DTSGlobalVariables.parent
startDate = DTSGlobalVariables("startDate")
Set oConnection = oPkg.Connections("db_conn2")
Set oTask = oPkg.tasks.new("DTSExecuteSQLTask")
oTask.Name = "DTSTask_DTSExecuteSQLTask_1"
Set oCustomerTask = oTask.CustomTask
oCustomerTask.Name = "DTSTask_DTSExecuteSQLTask_1"
oCustomerTask.description = "test task"
oCustomerTask.ConnectionID=oConnection.id
oCustomerTask.CommandTimeout=0
oCustomerTask.OutputAsRecordset = False
oCustomerTask.SQLStatement = "delete from tmp_table"
oCustomerTask.execute oPkg, Nothing, Nothing,
DTSTaskExecResult_Success
Set oCustomerTask = Nothing
set oTask=Nothing
Set oConnection=Nothing
set oPkg=nothing
Main = DTSTaskExecResult_Success
End Function
What's wrong?
Thanks in advance.I have found the resolution, after you create the task, you need
create a step object whcih will refers this new created task, you also
need add the task to current package. And then execute the step, you
can get the result. After the step complets, you need to remove the
task from package.
This solution works for me, but I do not know this is the best
solution or not. If anybody has more better solution, please post it.
Thanks a lot.
Following is the code which can run on my SQL Server 2000 Enterprise
Edition
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************
Function Main()
Dim oPkg, startDate, oTask, oConnection, oCustomerTask
Dim oResult
set oPkg = DTSGlobalVariables.parent
startDate = DTSGlobalVariables("startDate")
Set oConnection = oPkg.Connections("db_conn2")
'create task itself
Set oTask = oPkg.tasks.new("DTSExecuteSQLTask")
oTask.Name = "DTSTask_DTSExecuteSQLTask_1"
Set oCustomerTask = oTask.CustomTask
oCustomerTask.Name = "DTSTask_DTSExecuteSQLTask_1"
oCustomerTask.description = "test task"
oCustomerTask.ConnectionID=oConnection.id
oCustomerTask.CommandTimeout=0
oCustomerTask.OutputAsRecordset = False
oCustomerTask.SQLStatement = "select * from test_table"
oPkg.tasks.add oTask
'associate step with a task
Dim oStep
Set oStep = oPkg.Steps.New
oStep.Name = "DTSStep_DTSExecuteSQLTask_1"
oStep.Description = "Execute SQL Task: undefined"
oStep.ExecutionStatus = 1
oStep.TaskName = "DTSTask_DTSExecuteSQLTask_1"
oStep.CommitSuccess = False
oStep.RollbackFailure = False
oStep.ScriptLanguage = "VBScript"
oStep.AddGlobalVariables = True
oStep.RelativePriority = 3
oStep.CloseConnection = False
oStep.ExecuteInMainThread = False
oStep.IsPackageDSORowset = False
oStep.JoinTransactionIfPresent = False
oStep.DisableStep = False
oStep.FailPackageOnError = False
'run step
oStep.execute
'remove the added customer task
Dim index
For index=1 To oPkg.tasks.count
If (oPkg.tasks.item(index).name = "DTSTask_DTSExecuteSQLTask_1")
Then
oPkg.tasks.remove index
Exit For
End If
Next
Set oStep = Nothing
Set oCustomerTask = Nothing
set oTask=Nothing
Set oConnection=Nothing
set oPkg=nothing
Main = DTSTaskExecResult_Success
End Function

Tuesday, March 20, 2012

Rebuild all indexes in SQL 2008...

Friends, we use a command like:
EXECUTE master.dbo.xp_sqlmaint '-D THEDB -WriteHistory -RebldIdx 100'
or the command-lie equivalent to rebuild all indexes, and recommend this
technique to our clients. Apparently, .xp_sqlmaint and sqlmaint.exe will be
gone for SQL 2008.
For SQL 2008, what technique do you prefer/recommend for rebuilding all
indexes in all tables?
We add new tables to our product regularly as we add features, so we'd
prefer a solution that does not required specifying commands on a per-table
basis. Thanks in advance for your words!
Very sincerely,
James Hunter RossHave a look at the help in BOL under sys.dm_db_index_physical_stats. There
is an example (all the way near the bottom) on how to reindex each index
based on the fragmentation level. If you really wish to rebuild them all
(which I don't recommend) you can cut out the checks for the frag levels.
Oh and welcome back. Haven't seen you here for a while:).
--
Andrew J. Kelly SQL MVP
Solid Quality Mentors
"James Hunter Ross" <james.ross@.oneilsoft.com> wrote in message
news:uJVUiUjTIHA.5360@.TK2MSFTNGP03.phx.gbl...
> Friends, we use a command like:
> EXECUTE master.dbo.xp_sqlmaint '-D THEDB -WriteHistory -RebldIdx 100'
> or the command-lie equivalent to rebuild all indexes, and recommend this
> technique to our clients. Apparently, .xp_sqlmaint and sqlmaint.exe will
> be gone for SQL 2008.
> For SQL 2008, what technique do you prefer/recommend for rebuilding all
> indexes in all tables?
> We add new tables to our product regularly as we add features, so we'd
> prefer a solution that does not required specifying commands on a
> per-table basis. Thanks in advance for your words!
> Very sincerely,
> James Hunter Ross
>|||Thank you Andrew, that's what I need!
Yeah, I've been hiding away with SQL Server Compact Edition 3.1/3.5 and lots
of Windows Mobile barcode scanning devices for the last year or more. The
CE newsgroups are not nearly as active! Our server-side stuff is being
redied for SQL Server 2008 so I've come up for air recently.
James
"Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
news:OqwxMCkTIHA.4280@.TK2MSFTNGP06.phx.gbl...
> Have a look at the help in BOL under sys.dm_db_index_physical_stats. There
> is an example (all the way near the bottom) on how to reindex each index
> based on the fragmentation level. If you really wish to rebuild them all
> (which I don't recommend) you can cut out the checks for the frag levels.
> Oh and welcome back. Haven't seen you here for a while:).
> --
> Andrew J. Kelly SQL MVP
> Solid Quality Mentors
>
> "James Hunter Ross" <james.ross@.oneilsoft.com> wrote in message
> news:uJVUiUjTIHA.5360@.TK2MSFTNGP03.phx.gbl...
>> Friends, we use a command like:
>> EXECUTE master.dbo.xp_sqlmaint '-D THEDB -WriteHistory -RebldIdx 100'
>> or the command-lie equivalent to rebuild all indexes, and recommend this
>> technique to our clients. Apparently, .xp_sqlmaint and sqlmaint.exe will
>> be gone for SQL 2008.
>> For SQL 2008, what technique do you prefer/recommend for rebuilding all
>> indexes in all tables?
>> We add new tables to our product regularly as we add features, so we'd
>> prefer a solution that does not required specifying commands on a
>> per-table basis. Thanks in advance for your words!
>> Very sincerely,
>> James Hunter Ross
>>
>|||Enjoy the sunshine while you can!! :-)
You may wish to limit the items you rebuild to those > 1000 pages (a number
I think Microsoft recommends IIRC). I would definitely not bother with
items < 100 pages.
--
Kevin G. Boles
Indicium Resources, Inc.
SQL Server MVP
kgboles a earthlink dt net
"James Hunter Ross" <james.ross@.oneilsoft.com> wrote in message
news:uAvvw$kTIHA.4104@.TK2MSFTNGP05.phx.gbl...
> Thank you Andrew, that's what I need!
> Yeah, I've been hiding away with SQL Server Compact Edition 3.1/3.5 and
> lots of Windows Mobile barcode scanning devices for the last year or more.
> The CE newsgroups are not nearly as active! Our server-side stuff is
> being redied for SQL Server 2008 so I've come up for air recently.
> James
>
> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
> news:OqwxMCkTIHA.4280@.TK2MSFTNGP06.phx.gbl...
>> Have a look at the help in BOL under sys.dm_db_index_physical_stats.
>> There is an example (all the way near the bottom) on how to reindex each
>> index based on the fragmentation level. If you really wish to rebuild
>> them all (which I don't recommend) you can cut out the checks for the
>> frag levels.
>> Oh and welcome back. Haven't seen you here for a while:).
>> --
>> Andrew J. Kelly SQL MVP
>> Solid Quality Mentors
>>
>> "James Hunter Ross" <james.ross@.oneilsoft.com> wrote in message
>> news:uJVUiUjTIHA.5360@.TK2MSFTNGP03.phx.gbl...
>> Friends, we use a command like:
>> EXECUTE master.dbo.xp_sqlmaint '-D THEDB -WriteHistory -RebldIdx 100'
>> or the command-lie equivalent to rebuild all indexes, and recommend this
>> technique to our clients. Apparently, .xp_sqlmaint and sqlmaint.exe
>> will be gone for SQL 2008.
>> For SQL 2008, what technique do you prefer/recommend for rebuilding all
>> indexes in all tables?
>> We add new tables to our product regularly as we add features, so we'd
>> prefer a solution that does not required specifying commands on a
>> per-table basis. Thanks in advance for your words!
>> Very sincerely,
>> James Hunter Ross
>>
>|||Good point Kevin, thanks. (I sure enjoyed just letting SQLMaint.exe figure
everything out, even it it did adopt a brutish approach.)
James
"TheSQLGuru" <kgboles@.earthlink.net> wrote in message
news:13nqoerop5shq62@.corp.supernews.com...
> Enjoy the sunshine while you can!! :-)
> You may wish to limit the items you rebuild to those > 1000 pages (a
> number I think Microsoft recommends IIRC). I would definitely not bother
> with items < 100 pages.
> --
> Kevin G. Boles
> Indicium Resources, Inc.
> SQL Server MVP
> kgboles a earthlink dt net
>
> "James Hunter Ross" <james.ross@.oneilsoft.com> wrote in message
> news:uAvvw$kTIHA.4104@.TK2MSFTNGP05.phx.gbl...
>> Thank you Andrew, that's what I need!
>> Yeah, I've been hiding away with SQL Server Compact Edition 3.1/3.5 and
>> lots of Windows Mobile barcode scanning devices for the last year or
>> more. The CE newsgroups are not nearly as active! Our server-side stuff
>> is being redied for SQL Server 2008 so I've come up for air recently.
>> James
>>
>> "Andrew J. Kelly" <sqlmvpnooospam@.shadhawk.com> wrote in message
>> news:OqwxMCkTIHA.4280@.TK2MSFTNGP06.phx.gbl...
>> Have a look at the help in BOL under sys.dm_db_index_physical_stats.
>> There is an example (all the way near the bottom) on how to reindex each
>> index based on the fragmentation level. If you really wish to rebuild
>> them all (which I don't recommend) you can cut out the checks for the
>> frag levels.
>> Oh and welcome back. Haven't seen you here for a while:).
>> --
>> Andrew J. Kelly SQL MVP
>> Solid Quality Mentors
>>
>> "James Hunter Ross" <james.ross@.oneilsoft.com> wrote in message
>> news:uJVUiUjTIHA.5360@.TK2MSFTNGP03.phx.gbl...
>> Friends, we use a command like:
>> EXECUTE master.dbo.xp_sqlmaint '-D THEDB -WriteHistory -RebldIdx 100'
>> or the command-lie equivalent to rebuild all indexes, and recommend
>> this technique to our clients. Apparently, .xp_sqlmaint and
>> sqlmaint.exe will be gone for SQL 2008.
>> For SQL 2008, what technique do you prefer/recommend for rebuilding all
>> indexes in all tables?
>> We add new tables to our product regularly as we add features, so we'd
>> prefer a solution that does not required specifying commands on a
>> per-table basis. Thanks in advance for your words!
>> Very sincerely,
>> James Hunter Ross
>>
>>
>

Wednesday, March 7, 2012

Really need help w/ what should be simple question!

Hello,

Basically, all I am trying to do is create an SSIS pkg that will read a list of stored procedures from a table. I set up an EXECUTE SQL TASK to do this. I am saving the result set to a variable (type object).

Next, I call a FOREACHLOOP container, which references the variable from the EXECUTE SQL TASK.

But I'm not sure what to do next? I just want the FOR EACH LOOP to simply execute the stored procedure name as given by the first EXECUTE SQL TASK.

I was thinking to put another EXECUTE SQL TASK inside the FOR EACH LOOP, but I don't know how to reference the stored procedure name correctly, or if this is even allowable.

I am not a scripter :-)

Can you please offer me some advice on what to do next? I am desperately seeking a solution.

Thank you!!!

In the Variable Mappings tab of your For Each container, make sure that you are mapping the necessary columns (like the stored proc name) of your resultset to variables.

Create a new variable to hold the call to the stored procedure. In the properties for the variable, make sure EvaluateAsExpression is true. In the Expression property, construct the string for a call to the stored proc, using the variables you mapped in the For Each container. Add an Execute SQL task in your For Each container, and set the SQLSourceType to variable. Then pick the variable you created as the SourceVariable.

If you wait a bit, I'll post an example on my blog.

|||

Example:

http://agilebi.com/cs/blogs/jwelch/archive/2007/03/21/using-for-each-to-iterate-a-resultset.aspx

The sample package is attached to the post.

Hope this helps.

|||

Hi John,

I looked *everywhere*, and I honestly don't see where to set "EvaluateAsExpression" is true. That is, where in the world do I set the properties for the variable in the FOREACH containter editor? I really don't see this anywhere.

I also looked at your example from your post, and I don't see this anywhere, either?

Thanks

|||

Hi John,

I examined your example very carefully. However, I don't know what you mean by the statement:

There is a variable named "select". This variable uses an expression to build the following select statement: "SELECT ID, ParentID, ChildName FROM ChildTable WHERE ParentID = " + the "parentID" variable. The "select" variable is then used in another Execute SQL task.

Where are you building the expression? I don't see it.

Thanks

|||Select the variable in the variables window (not in the container editor) and hit F4. This should bring up the properties for the variable. EvaluateAsExpression is an option in that window. This is also where the expression is defined.|||

Are you talking about the DataObjectVariable under EnumeratorProperties in the Properties of the ForEachLoop container?

I see my the name of my ADO Object Source Variable (User::Reports) , but not the mapped column (User::report_name) > which contains the name of the stored procedure.

But hitting F4 does not bring up anything.

?

Thanks

|||

I think I may be getting "closer", in spite of things probably not being set correctly at this point.

So far I have an EXEC SQL task >> FOREACHLOOP >> EXEC SQL task.

And it appears it is actually trying to RUN the stored procedure names. But I am getting this error. Do you think this has to do with my not setting the EvaluateAsExpression? Or something else? Thanks!

SSIS package "Migration - Run Report Comparison.dtsx" starting.

Error: 0xC002F210 at Execute SQL Task, Execute SQL Task: Executing the query "MY_STORED_PROC" failed with the following error: "Parameter name is unrecognized.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

Task failed: Execute SQL Task

Warning: 0x80019002 at Foreach Loop Container: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

Warning: 0x80019002 at Migration - Run Report Comparison: SSIS Warning Code DTS_W_MAXIMUMERRORCOUNTREACHED. The Execution method succeeded, but the number of errors raised (1) reached the maximum allowed (1); resulting in failure. This occurs when the number of errors reaches the number specified in MaximumErrorCount. Change the MaximumErrorCount or fix the errors.

|||No, I'm talking about the window where you originally define the variable. On the menu bar for Visual Studio, choose SSIS..Variables, and you should see a list of variables defined in your package. You may need to click the "Show All Variables" button, as some variables may be scoped to specific items in the package.|||

Yes, I see it now, thanks so much for explaining this. I am very new to SSIS and packages in general.

So I set the variable which contains the stored procedure name EvaluateAsExpression as True.

However, I am still getting aforementioned error.

|||

Ha!

Figured it out. The devil is in the details as they say!

What was missing was that in the Parameter Mapping tab of the 2nd EXEC SQL TASK was that I needed to set the Parameter Name to 0.

I still don't fully understand the meaning of all the 0's, although I think it has something do with how OLEDB does things.

Anyhow, it's working... now onto step 2 - write outputs of sp's to name files.

Thanks again

Your example was very useful!!

|||

Could you mark the question as answered? Makes it easier for others to find answers for similar questions.

Thanks.

Saturday, February 25, 2012

Really confused in SQL statement

Hi there,

I'd like to execute an SQL query but i can not find a suitable way.Well i have one table contains :

Table 1 :
Id, CustNo, CustName, CustSurName, CustId1, CustId2,CustId3

Second Table contains :

Table 2 :

Id, WhNo, WhName, WhSurName, CustId1, CustId2,CustId3

As you see CustId1, CustId2,CustId3 is common.I would like to combine and show them in one table. It is simple with :
select a.* , b.* from Table1 a Table2 b ......(blah blah blah)

I select CustName rows from Table1 and can choose CustId1, CustId2, CustId3.But if i choose CustName (Customer Name) and it returns more than one row i can not match CustId's from Table2 and display in merged Query object.

Let me give an example :

select * from Table1 (where CustName = 'Joe') ;

gives these results :

Id, CustNo, CustName, CustSurName, CustId1, CustId2,CustId3

1,1,Joe,Black,1,1,1
2,2,Joe,Green,1,1,2
3,3,Joe,Blue,1,1,3

select * from Table2

gives these results :

Id, WhNo, WhName, WhSurName, CustId1, CustId2,CustId3

1,1,1,Apple,Peach,1,1,1
1,1,1,Apple2,Peach2,1,1,1
1,1,1,Apple3,Peach3,1,1,2
1,1,1,Apple4,Peach4,1,1,2
1,1,1,Apple5,Peach5,1,1,2
1,1,1,Apple6,Peach6,1,1,3
1,1,1,Apple7,Peach7,1,1,3
1,1,1,Apple8,Peach8,1,1,3
1,1,1,Apple9,Peach9,1,1,3
1,1,1,Apple10,Peach10,1,1,3

As you see 1,1,1,Joe,Black has 2 records in Table2 1,1,2,Joe,Green has 3 records in Table2 finally 1,1,3,Joe,Blue has 5 records in Table2.
Now i would like to select only name in Table1 and display merged table like this :

Table1 and Table 2 : (for example i choose "Joe" from Table 1 and the result is

1,1,Joe,Black,1,1,1,Apple,Peach
1,1,Joe,Black,1,1,1,Apple2,Peach2
2,2,Joe,Green,1,1,2,Apple3,Peach3
2,2,Joe,Green,1,1,2,Apple4,Peach4
2,2,Joe,Green,1,1,2,Apple5,Peach5
.
.
.
(goes like this)

As you see i want to select name from Table 1 and it should give merged table.I only have CustId1,CustId2,CustId3 as common field.

Thanks in advance.

AnalyzerTry this:

Select a.Id, a.CustNo, a.CustName, a.CustSurName
, a.CustId1, a.CustId2, a.CustId3
, b.WhName, b.WhSurName
From Table1 a, Table2 b
Where b.CustId3 = a.CustId3;

;)|||Hi,

Thank you for your reply but i can not select my list with this code because first of all i would like to select by name then Table 1 will return CustId numbers.Finally i'd like to make a merged list which contains Table1+Table2 values :(
Pat adviced me to use inner join for this.What is it?

Analyzer

P.S. By the way i didnt see an SQL section in the forum and i cross posted.I apologize for this.|||Which RDBMS software are you using?|||Well i am using MySQL 4.0+Borland C++ Builder 6.0 Ent+Zeos DBO 6.1.5|||Try something like:SELECT *
FROM table1
INNER JOIN table2
ON (table2.custId1 = table1.custId1
AND table2.custId2 = table1.custId2
AND table2.custId3 = table1.custId3)-PatP|||Hi Pat,

Thank you for your reply.But first i want to search on Customer Name then i would like to select columns from table2.I wrote this code :

SELECT * FROM table1 WHERE (CustName="John" and CustSurName="Blue") INNER JOIN table2 ON (table1.CustId1 = table2.CustId1 AND table1.CustId2 = table2.CustId2 AND table1.CustId3 = table2.CustId3)

But it does not work.Where is my fault?
I would like to explain more.For example John Blue purchased a printer, 2 DSL Modem and 1 monitor.I would like to search who named "John" and what did he purchased.
First of all i need to search name then i will search on CustId1,CustId2,CustId3.

I found this page : http://www.w3schools.com/sql/sql_join.asp but it does not elaborate.

Analyzer.|||Ok, i did it :)

SELECT * FROM table1 INNER JOIN table2 ON (table1.CustId1 = table2.CustId1 AND table1.CustId2 = table2.CustId2 AND table1.CustId3 = table2.CustId3) WHERE (CustName="John" and CustSurName="Blue")

Thank you for your all help.I appreciated it much.

Analyzer