473,513 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The multi-part identifier "..." could not be bound

20 New Member
Hi,

I am using SQL Server 2005. I have this stored procedure below but it doesn't work. It is for an archiving process I am currently implementing. The RiskArchive table has fields ArchiveID (primary key), RiskID, Criticality, MitigationActionID and ArchiveMonth (datetime data type). What I am trying to do is take the RiskID from the Risk table, the Criticality (a number showing how severe the risk is) for that risk and also any mitigations (MitigationActionID from the table Mitigation) for that risk. There can be many mitigations for each risk. In the Mitigation table, there is a RiskID field so that you can see which risk it belongs to.

First of all, I had this working at one stage. It was working before I put in the lines "if Risk.MitigationPlan = 'See action'", the "else" and the 3 lines of code after the else. But what I realised is that some risks might not have a mitigation when the stored procedure is run, so I implemented the if..else block that you see. The error that I get is:

Msg 4104, Level 16, State 1, Procedure usp_RiskArchive, Line 13
The multi-part identifier "Risk.MitigationPlan" could not be bound.

This error is on the if line, just before the insert into. Basically, when a mitigation has been entered for a risk, the MitigationPlan field for that risk is changed from None to See detail so that the user can see there are mitigations on that risk. So what I tried to do is when the MitigationPlan field for a risk is equal to See action, then insert the RiskID, Criticality and the MitigationActionID for that risk into the table RiskArchive, otherwise only insert the RiskID and Criticality (with the MitigationActionID field being left blank (null)). Note that this is what I want as I want a record of if there wasn't mitigations before, but are now, I can see when there wasn't any (by ArchiveMonth). The ArchiveMonth has a default value of getdate(). Here is the stored procedure:

Expand|Select|Wrap|Line Numbers
  1. USE [RiskAnalysis]
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. SET QUOTED_IDENTIFIER ON
  6. GO
  7.  
  8. alter PROCEDURE [dbo].[usp_RiskArchive] 
  9.  
  10. AS
  11.  
  12. SET NOCOUNT ON
  13.  
  14. IF NOT EXISTS
  15.     (SELECT RiskArchive.RiskID, RiskArchive.Criticality
  16.      FROM RiskArchive, Risk
  17.      WHERE RiskArchive.RiskID = Risk.RiskID AND RiskArchive.Criticality = Risk.Criticality)
  18.  
  19.     if Risk.MitigationPlan = 'See action'
  20.         INSERT INTO RiskArchive (RiskID, Criticality, MitigationActionID)
  21.         SELECT     Risk.RiskID, case when Risk.Criticality <> '' then Risk.Criticality else '' end, Mitigation.MitigationActionID
  22.         FROM Risk, Mitigation
  23.         WHERE Mitigation.RiskID = Risk.RiskID
  24.     else
  25.         INSERT INTO RiskArchive (RiskID, Criticality)
  26.         SELECT     Risk.RiskID, case when Risk.Criticality <> '' then Risk.Criticality else '' end
  27.         FROM Risk, Mitigation
  28.  
  29. set nocount off
  30.  
Any help on this will be much appreciated,

Andrew
Apr 11 '08 #1
3 5987
madankarmukta
308 Contributor
Hi,

It won't be possible in any case to check the value in the table just by writing
TableName.ColumnName at least in the scenario you have written since the compiler will look for the alias named "Risk".
The Useful solution over the scenario is to use CTE (Common table expression ) for the If..Then..else ..Part...You wrote about

Regards,
Mukta
Apr 11 '08 #2
ck9663
2,878 Recognized Expert Specialist
Hi,

I am using SQL Server 2005. I have this stored procedure below but it doesn't work. It is for an archiving process I am currently implementing. The RiskArchive table has fields ArchiveID (primary key), RiskID, Criticality, MitigationActionID and ArchiveMonth (datetime data type). What I am trying to do is take the RiskID from the Risk table, the Criticality (a number showing how severe the risk is) for that risk and also any mitigations (MitigationActionID from the table Mitigation) for that risk. There can be many mitigations for each risk. In the Mitigation table, there is a RiskID field so that you can see which risk it belongs to.

First of all, I had this working at one stage. It was working before I put in the lines "if Risk.MitigationPlan = 'See action'", the "else" and the 3 lines of code after the else. But what I realised is that some risks might not have a mitigation when the stored procedure is run, so I implemented the if..else block that you see. The error that I get is:

Msg 4104, Level 16, State 1, Procedure usp_RiskArchive, Line 13
The multi-part identifier "Risk.MitigationPlan" could not be bound.

This error is on the if line, just before the insert into. Basically, when a mitigation has been entered for a risk, the MitigationPlan field for that risk is changed from None to See detail so that the user can see there are mitigations on that risk. So what I tried to do is when the MitigationPlan field for a risk is equal to See action, then insert the RiskID, Criticality and the MitigationActionID for that risk into the table RiskArchive, otherwise only insert the RiskID and Criticality (with the MitigationActionID field being left blank (null)). Note that this is what I want as I want a record of if there wasn't mitigations before, but are now, I can see when there wasn't any (by ArchiveMonth). The ArchiveMonth has a default value of getdate(). Here is the stored procedure:

Expand|Select|Wrap|Line Numbers
  1. USE [RiskAnalysis]
  2. GO
  3. SET ANSI_NULLS ON
  4. GO
  5. SET QUOTED_IDENTIFIER ON
  6. GO
  7.  
  8. alter PROCEDURE [dbo].[usp_RiskArchive] 
  9.  
  10. AS
  11.  
  12. SET NOCOUNT ON
  13.  
  14. IF NOT EXISTS
  15.     (SELECT RiskArchive.RiskID, RiskArchive.Criticality
  16.      FROM RiskArchive, Risk
  17.      WHERE RiskArchive.RiskID = Risk.RiskID AND RiskArchive.Criticality = Risk.Criticality)
  18.  
  19.     if Risk.MitigationPlan = 'See action'
  20.         INSERT INTO RiskArchive (RiskID, Criticality, MitigationActionID)
  21.         SELECT     Risk.RiskID, case when Risk.Criticality <> '' then Risk.Criticality else '' end, Mitigation.MitigationActionID
  22.         FROM Risk, Mitigation
  23.         WHERE Mitigation.RiskID = Risk.RiskID
  24.     else
  25.         INSERT INTO RiskArchive (RiskID, Criticality)
  26.         SELECT     Risk.RiskID, case when Risk.Criticality <> '' then Risk.Criticality else '' end
  27.         FROM Risk, Mitigation
  28.  
  29. set nocount off
  30.  
Any help on this will be much appreciated,

Andrew

Two options:

1. Store Risk.MitigationPlan into a variable.

2. Create a dynamic query.


You're having problem because there are no tables open. The code that you wrote is fine in some database (foxpro, dbase, etc). Some of these, will keep the table open and the record pointer pointed to a record and will stay there until you move it or close the table. This is not the case in sql-server. SELECT, generally speaking, is the only way to read the value on the table.

-- CK
Apr 11 '08 #3
rdsandy
20 New Member
Im having a different problem with this stored procedure, but as its to do with a different error, I will make a new thread for it.
Apr 15 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

37
4833
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
4
4630
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
3843
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
3748
by: frankenberry | last post by:
I have multi-page tiff files. I need to extract individual frames from the multi-page tiffs and save them as single-page tiffs. 95% of the time I receive multi-page tiffs containing 1 or more black...
6
8140
by: cody | last post by:
What are multi file assemblies good for? What are the advantages of using multiple assemblies (A.DLL+B.DLL) vs. a single multi file assembly (A.DLL+A.NETMODULE)?
6
4870
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
4
17822
by: mimmo | last post by:
Hi! I should convert the accented letters of a string in the correspondent letters not accented. But when I compile with -Wall it give me: warning: multi-character character constant Do the...
5
5965
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
5
5704
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
0
2297
by: Sabri.Pllana | last post by:
We apologize if you receive multiple copies of this call for papers. *********************************************************************** 2008 International Workshop on Multi-Core Computing...
0
7260
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7161
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7525
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5089
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.