Click here to Skip to main content
15,912,205 members
Home / Discussions / Database
   

Database

 
GeneralRe: i want a to get a SQL Pin
R. Giskard Reventlov1-Jul-11 2:51
R. Giskard Reventlov1-Jul-11 2:51 
GeneralRe: i want a to get a SQL Pin
crocks2564-Jul-11 1:32
crocks2564-Jul-11 1:32 
QuestionAssistance with a Stored Proc working with the return results from another SP Pin
Alaric_29-Jun-11 5:47
professionalAlaric_29-Jun-11 5:47 
AnswerRe: Assistance with a Stored Proc working with the return results from another SP [modified] Pin
Alaric_29-Jun-11 6:35
professionalAlaric_29-Jun-11 6:35 
GeneralRe: Assistance with a Stored Proc working with the return results from another SP Pin
Alaric_29-Jun-11 11:23
professionalAlaric_29-Jun-11 11:23 
GeneralRe: Assistance with a Stored Proc working with the return results from another SP Pin
JOAT-MON30-Jun-11 8:22
JOAT-MON30-Jun-11 8:22 
GeneralRe: Assistance with a Stored Proc working with the return results from another SP Pin
Alaric_1-Jul-11 5:01
professionalAlaric_1-Jul-11 5:01 
GeneralRe: Assistance with a Stored Proc working with the return results from another SP Pin
Alaric_1-Jul-11 8:45
professionalAlaric_1-Jul-11 8:45 
Su-weet! Hurdle jumped. Below is a mock-up of the code that works for me
Manifest:
1) Table-Valued function created in Reporting that will encapsulate "campaign operation" specific querying logic.
2) Row inserted into CampaignOperations table with a pointer to (1)
3) Broker/Adapter procedure created that accepts a CampaignName and OperationCode

...found out along the way that an INSERT-EXEC stored proc cannot call an INSERT-EXEC stored proc and that you cannot execute remote table-valued functions.

Note that [RemoteSchema] is a schema located in a remote database called "Reporting." [LocalSchema] is the local schema that my application has access to. "Reporting" is a linked server of my local database.

1)
--------------------
USE [REPORTING]
GO

10:11:35 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE FUNCTION [RemoteSchema].[TakeAllTheMoneyAndWomens]()
RETURNS @Solicitations TABLE
(
  AccountId varchar(20) PRIMARY KEY NOT NULL,
  AccountNumber varchar(20) NOT NULL,
  HomePhone varchar(12) NULL,
  BusinessPhone varchar(12) NULL,
  FirstName varchar(70) NULL,
  LastName varchar(70) NULL,
  AddressStuffs varchar(max) NULL
)
AS
BEGIN
 INSERT @Solicitations
 SELECT '5','666321234','111-456-7890', '800-123-4567','Captain','Kirk','123 Menagerie Lane';
RETURN;
END;
GO


2)
------------------------------
insert into LocalSchema.CampaignOperations values('StarTrek','ShootToKill','REPORTING.RemoteSchema.TakeAllTheMoneyAndWomens()')


3)
------------------------------
USE [AppData]
GO
if(EXISTS(SELECT * FROM Information_Schema.ROUTINES where ROUTINE_SCHEMA = 'LocalSchema' and ROUTINE_TYPE = 'PROCEDURE' and ROUTINE_NAME = 'ExecuteCampaignOperation'))
	drop PROCEDURE [LocalSchema].[ExecuteCampaignOperation]
10:11:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [LocalSchema].[ExecuteCampaignOperation]
(
	@CampaignName varchar(50),
	@OperationCode varchar(10)
)
AS
BEGIN
    DECLARE @PROCEDURE nvarchar(100);
    DECLARE @SQL nvarchar(max);
	
    SELECT	@PROCEDURE = Operations.[Algorithm]
    FROM [LocalSchema].[CampaignOperations] [Operations]
    WHERE CampaignName = @CampaignName
      and OperationCode = @OperationCode; 
    SET @SQL = N'SELECT AccountNumber, AccountId, HomePhone, BusinessPhone, FirstName, LastName, AddressStuffs 
    FROM OpenQuery(REPORTING, ''SELECT * FROM ' + @PROCEDURE + ''')';
    EXECUTE sp_executesql @SQL;
    RETURN;
END

GO


EXEC LocalSchema.ExecuteCampaignOperation 'StarTrek', 'ShootToKill'

AccountNumber|AccountId|HomePhone|BusinessPhone|FirstName|LastName|AddressStuffs
1234567890	4	800-123-4567	800-231-4325	Captain	Kirk	123 Menagerie Lane.


Yaaaaaay!
"I need build Skynet. Plz send code"
modified formatting on Friday, July 1, 2011 2:59 PM

GeneralRe: Assistance with a Stored Proc working with the return results from another SP Pin
JOAT-MON1-Jul-11 8:56
JOAT-MON1-Jul-11 8:56 
Questionusing ?: operation in sql server 2008 Pin
reza assar29-Jun-11 3:47
reza assar29-Jun-11 3:47 
AnswerRe: using ?: operation in sql server 2008 Pin
dasblinkenlight29-Jun-11 4:29
dasblinkenlight29-Jun-11 4:29 
GeneralRe: using ?: operation in sql server 2008 Pin
reza assar29-Jun-11 5:35
reza assar29-Jun-11 5:35 
GeneralRe: using ?: operation in sql server 2008 Pin
dasblinkenlight29-Jun-11 5:58
dasblinkenlight29-Jun-11 5:58 
GeneralRe: using ?: operation in sql server 2008 Pin
reza assar29-Jun-11 7:36
reza assar29-Jun-11 7:36 
QuestionParameterised SQL Insert fails; plain text Insert works Pin
hairy_hats29-Jun-11 1:53
hairy_hats29-Jun-11 1:53 
AnswerRe: Parameterised SQL Insert fails; plain text Insert works Pin
Mycroft Holmes29-Jun-11 12:57
professionalMycroft Holmes29-Jun-11 12:57 
GeneralRe: Parameterised SQL Insert fails; plain text Insert works Pin
hairy_hats29-Jun-11 21:35
hairy_hats29-Jun-11 21:35 
AnswerRe: Parameterised SQL Insert fails; plain text Insert works Pin
dasblinkenlight29-Jun-11 17:30
dasblinkenlight29-Jun-11 17:30 
QuestionDTS not working in sql 2008 Pin
Robymon28-Jun-11 22:21
Robymon28-Jun-11 22:21 
AnswerRe: DTS not working in sql 2008 Pin
Corporal Agarn29-Jun-11 3:41
professionalCorporal Agarn29-Jun-11 3:41 
AnswerRe: DTS not working in sql 2008 Pin
Mycroft Holmes29-Jun-11 12:59
professionalMycroft Holmes29-Jun-11 12:59 
QuestionChanging DAO to ADO Pin
Kyudos28-Jun-11 14:34
Kyudos28-Jun-11 14:34 
AnswerRe: Changing DAO to ADO Pin
Kyudos28-Jun-11 14:39
Kyudos28-Jun-11 14:39 
Questioncheck the key value before inserting data [modified]---ALREADY SOLVED--- Pin
Dhyanga28-Jun-11 10:46
Dhyanga28-Jun-11 10:46 
AnswerRe: check the key value before inserting data Pin
UNCRushFan28-Jun-11 11:11
UNCRushFan28-Jun-11 11:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.