You are not logged in.

  • Login

1

Thursday, August 18th 2011, 6:33pm

MSSQL => Stored Procedure => Recordset

Hi!

Ich habe folgendes MS SQL Procedure

SQL Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
 
ALTER  PROCEDURE [dbo].[Recipient_EnumerateVE] (
	@Pending INT = 0,
	@JobPrefixId INT = 101,
	@JobId INT = 727,
	@RecipientId INT = 0,
	@FailedOnly INT = 0
)
 
AS
 
/* Description : Return list of recipients based on JobId and other supplied
 *		 parameters.  VENALI EXPRESS FLAVOUR
 * In          : @Pending - Return only recipients for jobs in a pending state
 *		 @JobPrefixId - Identifier of gateway submitting job
 *		 @JobId - Identifier of job whose recipients are to be returned
 *		 @RecipientId - Identifier of recipient to return
 *		 @FailedOnly - Return only those recipients with a completed
 *		 status of failed.
 * Out	       : Two recordsets:
 *			Summary Totals for job, listing successful, failed and
 *			pending recipients.  Values returned are based only on
 *			the JobId and do not reflect effects of other parameters.
 *			Recipient List, return all recipients that meet the
 *			selection parameters provided.
 * Notes       : Based on the selection criteria, return the list of recipients for
 *		 given job.  Create summary totals are return those as well.
 * History     :
 *
 * Date       Who Action    Notes
 * --------------------------------------------------------------------------
 * 13/07/2011 MAS Created
 */
 
DECLARE	@ReturnCode INT,
	@RecordCount INT,
	@JobSuccessCount INT,
	@JobFailureCount INT,
	@JobPendingCount INT,
	@SystemJobId INT,
	@MessageStringShort varchar(32),
	@MessageStringLong varchar(128)
 
SET NOCOUNT ON
 
	-- Logging: Start a System Job and log the SP parameters
	SELECT @MessageStringShort = 'Recipient_EnumerateWork<' + convert(varchar, @JobPrefixId) + '-' + convert(varchar, @JobId) + '>'
	EXEC @SystemJobId = [UTIL_BeginSystemJob]
		@JobType = 3,
		@JobTag = @MessageStringShort,
		@OwnerJobPrefixId = @JobPrefixId,
		@OwnerJobId = @JobId,
		@OwnerRecipientId = @RecipientId
 
	SELECT @MessageStringLong = 'Returning recipient list with the following parameters: @Pending = ' + convert(varchar, ISNULL(@Pending, 0)) + ', '
	SELECT @MessageStringLong = @MessageStringLong + '@JobPrefixId = ' + convert(varchar, ISNULL(@JobPrefixId, 0)) + ', '
	SELECT @MessageStringLong = @MessageStringLong + '@JobId = ' + convert(varchar, ISNULL(@JobId, 0)) + ', '
	SELECT @MessageStringLong = @MessageStringLong + '@RecipientId = ' + convert(varchar, ISNULL(@RecipientId, 0)) + ', '
	SELECT @MessageStringLong = @MessageStringLong + '@FailedOnly = ' + convert(varchar, ISNULL(@FailedOnly, 0))
 
	EXEC [dbo].[UTIL_LogSystemJobDetail]
		@JobId = @SystemJobId,
		@JobDetail = @MessageStringLong
 
	-- Create temporary table to hold the selected recipients
	CREATE TABLE #RecptResultSet(JobPrefixId INT NOT NULL, JobId INT NOT NULL, RecipientId INT NOT NULL,
		EventStatusId INT NOT NULL, EventDlvryECD VARCHAR(32) NULL, EventStopDt DATETIME NULL,
		EventFaxNumber VARCHAR(32) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , EventRecipientName NVARCHAR(64) NULL, EventRecipientCompanyName NVARCHAR(32) NULL,
		EventDlvryAttempts SMALLINT NOT NULL, ErrorSource INT NULL, ErrorCode INT NULL,
		ErrorClass INT NULL, ErrorExtra INT NULL, ErrorDesc VARCHAR(100) NULL, EventStatusDesc VARCHAR(100) NULL,
		EventSubmitDt DATETIME, EventStartDt DATETIME, EventDuration smallint, EventDlvrySpeed VARCHAR(8),
		DlvryServerRecptRecvCSID VARCHAR(39), PageCt int, CoverSubject NVARCHAR(128),UserField1 NVARCHAR(32),EventDlvryCurrentPageCt int,
		RecipTitle nvarchar (32) NULL,RecipFirstName nvarchar (32) NULL,RecipLastName nvarchar (32) NULL,
		RecipAddress1 nvarchar (55) NULL ,RecipAddress2 nvarchar (55) NULL ,RecipCity nvarchar (29) NULL,
		RecipState nvarchar (19) NULL ,RecipZip nvarchar (19) NULL ,RecipCountry nvarchar (35) NULL , RecipVoice nvarchar (34) NULL,
                RecipField1 nvarchar(32) NULL,
		RecipField2 nvarchar(32) NULL, RecipField3 nvarchar(32) NULL, RecipField4 nvarchar(32) NULL, RecipField5 nvarchar(32) NULL,
		RecipField6 nvarchar(32) NULL, RecipField7 nvarchar(32) NULL, RecipField8 nvarchar(32) NULL, RecipField9 nvarchar(32) NULL,
		RecipField10 nvarchar(32) NULL, RecipField11 nvarchar(32) NULL, RecipField12 nvarchar(32) NULL,
        	SenderName nvarchar (64) NULL, SenderCompany nvarchar (34) NULL,SenderAddress1 nvarchar (55) NULL,
                SenderAddress2 nvarchar (55) NULL,SenderCity nvarchar (29) NULL,SenderState nvarchar (19) NULL,SenderZip nvarchar (19) NULL,
                SenderCountry nvarchar (35) NULL,SenderVoice nvarchar (34) NULL,SenderFax nvarchar (34) NULL,
                EventFaxNumberCountryCode VARCHAR(8) NULL , EventFaxNumberCountryName VARCHAR(64) NULL ,
                FailureBRIPErrorDesc VARCHAR(100) NULL, FailureBRIPErrorCode INT NULL,
                FailureReportLongString VARCHAR(23) NULL,
                FailureErrorEmailNotification VARCHAR(1000) NULL, FailureErrorWSResponse VARCHAR(1000) NULL
                )
 
	-- Initialise
	SELECT	@ReturnCode = 0,
		@RecordCount = 0,
		@JobSuccessCount = 0,
		@JobFailureCount = 0,
		@JobPendingCount = 0
 
	-- Get completed as well as pending recipients
	INSERT	#RecptResultSet(JobPrefixId, JobId, RecipientId, EventStatusId, EventDlvryECD, EventStopDt, EventFaxNumber,
		EventRecipientName, EventRecipientCompanyName, 	EventDlvryAttempts, ErrorSource, ErrorCode, ErrorClass,
		ErrorExtra, ErrorDesc, EventStatusDesc, EventSubmitDt, EventStartDt, EventDuration, EventDlvrySpeed,
		DlvryServerRecptRecvCSID, PageCt, CoverSubject, UserField1,EventDlvryCurrentPageCt,
		RecipTitle,RecipFirstName,RecipLastName,RecipAddress1,RecipAddress2,RecipCity,
		RecipState,RecipZip,RecipCountry,RecipVoice,
                RecipField1,RecipField2,RecipField3,RecipField4,RecipField5,RecipField6,
                RecipField7,RecipField8,RecipField9,RecipField10,RecipField11,RecipField12,
        	SenderName,SenderCompany,SenderAddress1,
                SenderAddress2,SenderCity,SenderState,SenderZip,
                SenderCountry,SenderVoice,SenderFax)
                EXEC [dbo].[Recipient_EnumerateWorker] 	@Pending, @JobPrefixId, @JobId, @RecipientId, @FailedOnly, 
                                                        @RecordCount OUTPUT, @JobSuccessCount OUTPUT, @JobFailureCount OUTPUT, @JobPendingCount OUTPUT
 
	CREATE NONCLUSTERED INDEX [idx_RecipientJobId] ON #RecptResultSet
	(
		[JobPrefixId], [JobId], [RecipientId]
	)
 
	EXEC [dbo].[UTIL_LogSystemJobDetail]
		@JobId = @SystemJobId,
		@JobDetail = 'Adding EventFaxNumber details'
 
	-- Get the friendly description of the event status
	UPDATE	r
	SET	EventFaxNumberCountryCode = '1',
                EventFaxNumberCountryName = 'USA/Canada'
	FROM	#RecptResultSet r
        WHERE LEFT(EventFaxNumber,1) = '1'
 
	UPDATE	r
	SET	EventFaxNumberCountryCode = idc.DialingCode,
                EventFaxNumberCountryName = idc.CountryName
	FROM	#RecptResultSet r
	INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
        WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 6
 
	UPDATE	r
	SET	EventFaxNumberCountryCode = idc.DialingCode,
                EventFaxNumberCountryName = idc.CountryName
	FROM	#RecptResultSet r
	INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
        WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 5
 
	UPDATE	r
	SET	EventFaxNumberCountryCode = idc.DialingCode,
                EventFaxNumberCountryName = idc.CountryName
	FROM	#RecptResultSet r
	INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
        WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 4
 
	UPDATE	r
	SET	EventFaxNumberCountryCode = idc.DialingCode,
                EventFaxNumberCountryName = idc.CountryName
	FROM	#RecptResultSet r
	INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
       WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 3
 
	UPDATE	r
	SET	EventFaxNumberCountryCode = idc.DialingCode,
                EventFaxNumberCountryName = idc.CountryName
	FROM	#RecptResultSet r
	INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
        WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 2
 
	UPDATE	r
	SET	EventFaxNumberCountryCode = idc.DialingCode,
                EventFaxNumberCountryName = idc.CountryName
	FROM	#RecptResultSet r
	INNER JOIN InternationalDialCodes idc ON SUBSTRING(EventFaxNumber,4,LEN(idc.DialingCode)) = idc.DialingCode
        WHERE LEFT(EventFaxNumber,3) = '011' AND LEN(idc.DIalingCode) = 1
 
	EXEC [dbo].[UTIL_LogSystemJobDetail]
		@JobId = @SystemJobId,
		@JobDetail = 'Added Failure details'
 
	UPDATE	r
	SET	FailureBRIPErrorDesc = 'Success',
		FailureBRIPErrorCode = 0,
		FailureReportLongString = 'Success'
	FROM	#RecptResultSet r
        WHERE EventStatusId=1
 
	UPDATE	r
	SET	FailureBRIPErrorDesc = em.BRIPErrorDesc,
		FailureBRIPErrorCode = em.BRIPErrorCode,
		FailureReportLongString = em.ReportLongString,
		FailureErrorEmailNotification = em.ErrorEmailNotification,
		FailureErrorWSResponse = em.ErrorWSResponse
	FROM	#RecptResultSet r
	INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
                                       r.ErrorClass=em.ECDErrortype AND
                                       r.ErrorCode=em.ECDErrorCode AND
                                       r.ErrorExtra=em.ECDErrorExtra
        WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
 
	UPDATE	r
	SET	FailureBRIPErrorDesc = em.BRIPErrorDesc,
		FailureBRIPErrorCode = em.BRIPErrorCode,
		FailureReportLongString = em.ReportLongString,
		FailureErrorEmailNotification = em.ErrorEmailNotification,
		FailureErrorWSResponse = em.ErrorWSResponse
	FROM	#RecptResultSet r
	INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
                                       r.ErrorClass=em.ECDErrortype AND
                                       r.ErrorCode=em.ECDErrorCode AND
                                       0=em.ECDErrorExtra
        WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
 
	UPDATE	r
	SET	FailureBRIPErrorDesc = em.BRIPErrorDesc,
		FailureBRIPErrorCode = em.BRIPErrorCode,
		FailureReportLongString = em.ReportLongString,
		FailureErrorEmailNotification = em.ErrorEmailNotification,
		FailureErrorWSResponse = em.ErrorWSResponse
	FROM	#RecptResultSet r
	INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
                                       r.ErrorClass=em.ECDErrortype AND
                                       0=em.ECDErrorCode AND
                                       0=em.ECDErrorExtra
        WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
 
	UPDATE	r
	SET	FailureBRIPErrorDesc = em.BRIPErrorDesc,
		FailureBRIPErrorCode = em.BRIPErrorCode,
		FailureReportLongString = em.ReportLongString,
		FailureErrorEmailNotification = em.ErrorEmailNotification,
		FailureErrorWSResponse = em.ErrorWSResponse
	FROM	#RecptResultSet r
	INNER JOIN ErrorMappings em ON r.ErrorSource=em.ECDErrorSource AND
                                       0=em.ECDErrortype AND
                                       0=em.ECDErrorCode AND
                                       0=em.ECDErrorExtra
        WHERE EventStatusId=2 AND FailureBRIPErrorDesc IS NULL
 
	-- Return the summary totals for the Job
	SELECT 	@RecordCount AS [RecordCount],	
		@JobSuccessCount AS [JobSuccessCount],
		@JobFailureCount AS [JobFailureCount],
		@JobPendingCount AS [JobPendingCount]
 
	EXEC [dbo].[UTIL_LogSystemJobDetail]
		@JobId = @SystemJobId,
		@JobDetail = 'Returning recipient list'
 
	-- Return the list of all recipients for the Job
	SELECT	*
	FROM 	#RecptResultSet
	ORDER BY JobPrefixId,
		JobId,
		RecipientId
 
	EXEC [dbo].[UTIL_LogSystemJobDetail]
		@JobId = @SystemJobId,
		@JobDetail = 'Recipient list return complete'
 
	-- Destroy temporary objects
	DROP
	TABLE	#RecptResultSet
 
	EXEC [dbo].[UTIL_EndSystemJob]
		@JobId = @SystemJobId
 
SET NOCOUNT OFF
 
	RETURN @ReturnCode
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


Ich versuche folgendermaßen an das zweite OUTPUT Recordset zu kommen:

PHP Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
 
$Pending = "0";  
$Prefix = "101";
$JobId = "315";
$RecipientId = "0";
$FailedOnly = "1";
 
// Connect to MSSQL and select the database
mssql_connect('expsq002', 'sa', 'MYPW!');
mssql_select_db('db_data');
 
// Create a new stored prodecure
$stmt = mssql_init('Recipient_Enumerate');
 
//mssql_bind($stmt, '@Pending',$Pending,SQLINT4,false,false,3);
mssql_bind($stmt, '@JobPrefixId',$Prefix,SQLINT4,false,false,3);
mssql_bind($stmt, '@JobId',$JobId,SQLINT4,false,false,3);
//mssql_bind($stmt, '@RecipientId',$RecipientId,SQLINT4,false,false,3);
//mssql_bind($stmt, '@FailedOnly',$FailedOnly,SQLINT4,false,false,3);
 
//mssql_bind($stmt, "@ReturnCode", $lala, SQLVARCHAR, true, true);
$result = mssql_execute($stmt);
$numProds = mssql_num_rows($result); 
while($row = mssql_fetch_row($result))
 
{
var_dump($row);
 
 
}
 
 
 
 
?>


Ich bekomme leider als Antwort:

HTML Code

1
Warning: mssql_execute(): message: Cannot insert the value NULL into column '', table ''; column does not allow nulls. INSERT fails. (severity 16) in /var/www/reporting/test.php on line 23 Warning: mssql_execute(): General SQL Server error: Check messages from the SQL Server (severity 16) in /var/www/reporting/test.php on line 23 array(4) { [0]=> int(0) [1]=> int(0) [2]=> int(0) [3]=> int(0) }


Kann mir jemand weiterhelfen? Ich hatte noch nie mit SP's zu tun und das sind meine ersten Gehversuche in dieser Richtung. Per SQL-Query Tool funktioniert es mit diesen Parametern einwandfrei :(

Gruß,
Matze

2

Friday, August 19th 2011, 7:22pm

Also weil das absolut nichts mit PHP zu tun hat, verschiebe ich das mal ins Datenbank Forum.

Ansonsten kann ich mich mit MSSQL nicht gut genug aus um dir die Frage direkt beantworten zu können, aber es sieht schlicht danach aus als, als hättest du ein paar Variablen vergessen zu setzen.
Welche setzt du denn noch zusätzlich im SQL Browser. In deinem PHP Code hast du ja ein paar Variablen auskommentiert.

3

Friday, August 19th 2011, 8:21pm

Hi Torben,

Ich habe nochmal mit dem DBA gesprochen, es sieht so aus als würde er eine TEMP Table füllen wollen, und PHP verhält sich hier falsch, hat irgendwas mit ANSI NULL settings zu tun, meiner Meinung nach müsste aber der DBA diese in der Stored Procedure setzen, nicht ich ... darüber streiten wir aktuell, oder liege ich da etwa falsch?

Matze

4

Saturday, August 20th 2011, 10:09am

Hi,

was gibt der Server denn für eine Fehlermeldung aus?

Quoted

General SQL Server error: Check messages from the SQL Server


Wie sieht dein $stmt aus ?
Die angehangenen SQL Befehle kannst du so nicht als 1 Statement nutzen, da du einzelnen Befehle mit einem Semikolon abschließen musst.

Also SELECT ...... ; ALTER ..... ; usw.

Social bookmarks