Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 problem in stored procedure

Author  Topic 

sumit.attari
Starting Member

1 Post

Posted - 2009-01-27 : 02:24:16
step -1 Made stored procedure
ALTER proc [dbo].[spFindDirectory]
(@vquery Nvarchar(500) )

as
begin
EXEC sp_executesql @vquery
end


step -2 Execute stored procedure

exec [proces1] 'SELECT distinct crmcontactid.Mail as email,tbl_Directory.I_Id as Id,tbl_Directory.T_Emp_Id, tbl_Area_1.AreaCode ,crmcontactid.tel as Office_No, tbl_Area_2.AreaCode , crmcontactid.HomePhone AS Home_No, tbl_Area.AreaCode as faxAreaCode, crmcontactid.fax AS Fax_No, crmcontactid.HMobile as Mobile_No, tbl_AdminDepartment.AdminDeptName as AdminDeptName,tbl_Department.deptName as DepartmentName, tbl_Area_3.AreaCode ,tbl_Directory.PhoneNo_Rail_O as Phone_Rail_O, tbl_Area_4.AreaCode ,tbl_Directory.PhoneNo_Rail_R as Phone_Rail_R, tbl_Area_5.AreaCode ,tbl_Directory.PhoneNo_MTNL_O as Phone_MTNL_O, tbl_Area_6.AreaCode ,tbl_Directory.PhoneNo_MTNL_R as Phone_MTNL_R, crmcontactid.GivenName as FName_E,crmcontactid.sn as LName_E,tbl_Directory.T_Name_F_H as FName_H,tbl_Directory.T_Name_L_H as LName_H, crmcontactid.HStreet as Street,crmcontactid.HCity as City, crmcontactid.HState as State, tbl_Directory.DT_DateTillPost as DateTillPost, tbl_Priority.T_PriorityName as Priority, tbl_Branch.T_BranchName as Branch, tbl_HeadQuarter.T_HQName as HeadQuarter, tbl_Rank.T_RankName as Rank
FROM tbl_Directory INNER JOIN tbl_Area AS tbl_Area_1 ON tbl_Directory.AreaId_O = tbl_Area_1.AreaId INNER JOIN tbl_Area AS tbl_Area_2 ON tbl_Directory.AreaId_H = tbl_Area_2.AreaId INNER JOIN tbl_Area AS tbl_Area_3 ON tbl_Directory.AreaId_Rail_O = tbl_Area_3.AreaId INNER JOIN tbl_Area AS tbl_Area_4 ON tbl_Directory.AreaId_Rail_R = tbl_Area_4.AreaId INNER JOIN tbl_Area AS tbl_Area_5 ON tbl_Directory.AreaId_MTNL_O = tbl_Area_5.AreaId INNER JOIN tbl_Area AS tbl_Area_6 ON tbl_Directory.AreaId_MTNL_R = tbl_Area_6.AreaId INNER JOIN tbl_Area ON tbl_Directory.AreaId_F = tbl_Area.AreaId INNER JOIN crmcontactid ON tbl_Directory.I_Id = crmcontactid.AtxContactID INNER JOIN tbl_Priority ON tbl_Directory.I_PriorityId = tbl_Priority.I_PriorityId INNER JOIN tbl_Branch ON tbl_Directory.I_BranchId = tbl_Branch.I_BranchId INNER JOIN tbl_HeadQuarter ON tbl_Directory.I_HQId = tbl_HeadQuarter.I_HQId INNER JOIN tbl_Rank ON tbl_Directory.I_Rank = tbl_Rank.I_RankId INNER JOIN tbl_AdminDepartment ON tbl_Directory.I_AdminDept_Id = tbl_AdminDepartment.AdminDept_Id INNER JOIN tbl_Department ON crmcontactid.Department = tbl_Department.Dept_Id where tbl_Directory.I_id = tbl_Directory.I_id'

Now I am getting some error-----

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "crmcontactid.HMobile" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "tbl_AdminDepartment.AdminDeptName" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "tbl_Department.deptName" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "tbl_Area_3.AreaCode" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "tbl_Directory.PhoneNo_Rail_O" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "tbl_Area_4.AreaCode" could not be bound.
Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "tbl_Directory.Pho" could not be bound.

please help me

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-27 : 02:27:45
Please check the aliasnames for tables, verify the column names
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-01-27 : 04:02:35
Formatted with http://www.wangz.net/cgi-bin/pp/gsqlparser/sqlpp/sqlformat.tpl
Maybe it helps helping
/* Powered by General SQL Parser (www.sqlparser.com) */

SELECT DISTINCT CRMCONTACTID.MAIL AS EMAIL,
TBL_DIRECTORY.I_ID AS ID,
TBL_DIRECTORY.T_EMP_ID,
TBL_AREA_1.AREACODE,
CRMCONTACTID.TEL AS OFFICE_NO,
TBL_AREA_2.AREACODE,
CRMCONTACTID.HOMEPHONE AS HOME_NO,
TBL_AREA.AREACODE AS FAXAREACODE,
CRMCONTACTID.FAX AS FAX_NO,
CRMCONTACTID.HMOBILE AS MOBILE_NO,
TBL_ADMINDEPARTMENT.ADMINDEPTNAME AS ADMINDEPTNAME,
TBL_DEPARTMENT.DEPTNAME AS DEPARTMENTNAME,
TBL_AREA_3.AREACODE,
TBL_DIRECTORY.PHONENO_RAIL_O AS PHONE_RAIL_O,
TBL_AREA_4.AREACODE,
TBL_DIRECTORY.PHONENO_RAIL_R AS PHONE_RAIL_R,
TBL_AREA_5.AREACODE,
TBL_DIRECTORY.PHONENO_MTNL_O AS PHONE_MTNL_O,
TBL_AREA_6.AREACODE,
TBL_DIRECTORY.PHONENO_MTNL_R AS PHONE_MTNL_R,
CRMCONTACTID.GIVENNAME AS FNAME_E,
CRMCONTACTID.SN AS LNAME_E,
TBL_DIRECTORY.T_NAME_F_H AS FNAME_H,
TBL_DIRECTORY.T_NAME_L_H AS LNAME_H,
CRMCONTACTID.HSTREET AS STREET,
CRMCONTACTID.HCITY AS CITY,
CRMCONTACTID.HSTATE AS STATE,
TBL_DIRECTORY.DT_DATETILLPOST AS DATETILLPOST,
TBL_PRIORITY.T_PRIORITYNAME AS PRIORITY,
TBL_BRANCH.T_BRANCHNAME AS BRANCH,
TBL_HEADQUARTER.T_HQNAME AS HEADQUARTER,
TBL_RANK.T_RANKNAME AS RANK
FROM TBL_DIRECTORY
INNER JOIN TBL_AREA AS TBL_AREA_1
ON TBL_DIRECTORY.AREAID_O = TBL_AREA_1.AREAID
INNER JOIN TBL_AREA AS TBL_AREA_2
ON TBL_DIRECTORY.AREAID_H = TBL_AREA_2.AREAID
INNER JOIN TBL_AREA AS TBL_AREA_3
ON TBL_DIRECTORY.AREAID_RAIL_O = TBL_AREA_3.AREAID
INNER JOIN TBL_AREA AS TBL_AREA_4
ON TBL_DIRECTORY.AREAID_RAIL_R = TBL_AREA_4.AREAID
INNER JOIN TBL_AREA AS TBL_AREA_5
ON TBL_DIRECTORY.AREAID_MTNL_O = TBL_AREA_5.AREAID
INNER JOIN TBL_AREA AS TBL_AREA_6
ON TBL_DIRECTORY.AREAID_MTNL_R = TBL_AREA_6.AREAID
INNER JOIN TBL_AREA
ON TBL_DIRECTORY.AREAID_F = TBL_AREA.AREAID
INNER JOIN CRMCONTACTID
ON TBL_DIRECTORY.I_ID = CRMCONTACTID.ATXCONTACTID
INNER JOIN TBL_PRIORITY
ON TBL_DIRECTORY.I_PRIORITYID = TBL_PRIORITY.I_PRIORITYID
INNER JOIN TBL_BRANCH
ON TBL_DIRECTORY.I_BRANCHID = TBL_BRANCH.I_BRANCHID
INNER JOIN TBL_HEADQUARTER
ON TBL_DIRECTORY.I_HQID = TBL_HEADQUARTER.I_HQID
INNER JOIN TBL_RANK
ON TBL_DIRECTORY.I_RANK = TBL_RANK.I_RANKID
INNER JOIN TBL_ADMINDEPARTMENT
ON TBL_DIRECTORY.I_ADMINDEPT_ID = TBL_ADMINDEPARTMENT.ADMINDEPT_ID
INNER JOIN TBL_DEPARTMENT
ON CRMCONTACTID.DEPARTMENT = TBL_DEPARTMENT.DEPT_ID
WHERE TBL_DIRECTORY.I_ID = TBL_DIRECTORY.I_ID




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-27 : 08:42:07
why do you want pass the whole query through parameter of sp?
Go to Top of Page
   

- Advertisement -