Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
I have created a stored procedure:
CREATE PROCEDURE TextStoreLogin
#user nvarchar(30),
#flag bit
AS
BEGIN
IF #user IS NOT NULL AND #flag = 0
SELECT *
FROM login u
WHERE u.UserName = #user
END
I want to execute accept parameter redundant store:
EXEC TextStoreLogin #user = 'MB139986', #flag = 0, #hau = '0';
Thank you very much.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I want to calculate the time complexity of if-else statement inside a while loop but I am not sure how.
If you want to measure the elapsed time in the BEGIN END block;
[![DECLARE #Counter INT
DECLARE #TimeStart AS DATETIME
DECLARE #TimeStop AS DATETIME
SET #Counter=1
WHILE ( #Counter <= 10)
BEGIN
PRINT 'The counter value is = ' + CONVERT(VARCHAR,#Counter)
IF #Counter %4 =0
BEGIN
SET #TimeStart=GETDATE()
WAITFOR DELAY '00:00:001';
END
SET #TimeStop =GETDATE()
PRINT 'The elapsed time is = ' + CAST(DATEDIFF(MICROSECOND,#TimeStart,#TimeStop) AS VARCHAR(1000)) + ' microsecond'
SET #TimeStart= NULL
SET #TimeStop= NULL
SET #Counter = #Counter + 1
END
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
[]
I want to replace these column numbers <1700>/(<1027>-<1018>-<1019>-<1022>-<1020>)
Node column name
I think you are looking for something like this:
DECLARE #source VARCHAR(2000) = '<1027>-<1018>';
DECLARE #result VARCHAR(2000) = #source;
DECLARE #YourTable TABLE (
[Data] INT
, [Replacement] BIGINT
);
INSERT INTO #YourTable ([Data], [Replacement])
VALUES
(1700, -251158)
,(1027, 1482018)
,(1018, 75451);
SELECT #result = REPLACE(#result,CONCAT('<',[Data],'>'), [Replacement])
FROM #YourTable
SELECT #result
-- OUTPUT: 1482018-75451
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I can't create this stored procedure, the error tells me that the syntax of AS is incorrect. Please help! I have searched everywhere where my error could be or how I can redefine the stored procedure, and I have not had success.
IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N'[dbo].[PRC_BizAgi_Obtener_Anualidad]')
AND type in (N'P'))
BEGIN
DROP PROCEDURE [dbo].[PRC_BizAgi_Obtener_Anualidad]
END
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[PRC_BizAgi_Obtener_Anualidad]
#id_NinoCentro INT
AS
DECLARE #periodo INT
SET #periodo = YEAR(GETDATE())
/*SET #id_NinoCentro = ncp.id_Nino;*/
AS <-------- INCORRECT SYNTAX
BEGIN
SET NOCOUNT ON;
SELECT
ncp.id_NinoCentro,
CAST (MAX(ncp.Ano) AS VARCHAR)+''+
CASE
WHEN MAX(ncp.Mes) > 9
THEN CAST(MAX(ncp.Mes) AS VARCHAR)
ELSE '0'+ CAST(MAX(ncp.Mes) AS VARCHAR)
END AS periodo
FROM
nino_centro_pago ncp
WHERE
periodo = #periodo
AND ncp.id_NinoCentro = #id_NinoCentro
AND ProductoFlex = '101'
AND PagaInscr = 1
GROUP BY
ncp.id_NinoCentro
HAVING
COUNT(*) >= 6
END
Right after the parameters, you should have AS ... BEGIN ... and that's all - right now, you have the AS twice - right after the parameters, and again after declaring and setting the #periodo variable - you should have one AS only:
CREATE PROCEDURE [dbo].[PRC_BizAgi_Obtener_Anualidad]
#id_NinoCentro INT
AS
BEGIN
SET NOCOUNT ON;
DECLARE #periodo INT
SET #periodo = YEAR(GETDATE())
-- rest of your procedure here....
END
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
i have one sp with multiple resultsets like
Create procedure spNAME
As
Begin
select * from t1
select * from t2
select * from t3
END
now i want to create one stored procedure to find result of 3 statement in sp
Re-write your proc something like this..
Create procedure spNAME
#RS INT = NULL
As
Begin
IF (#RS = 1)
BEGIN
select * from t1
END
IF (#RS = 2)
BEGIN
select * from t2
END
IF (#RS = 3)
BEGIN
select * from t3
END
END
Now pass different parameter values to proc depending on what result set you want to return
Exec spNAME --<-- No Result set
Exec spNAME 1 --<-- Result set 1
Exec spNAME 2 --<-- Result set 2
Exec spNAME 3 --<-- Result set 3
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to display a label field with system generated value i.e alphanumeric value.So
is it possible to create a stored procedure which will return alphanumeric value, with auto increment value every time that it is executed.
where the alpha value will be constant like "ABC" only the numeric value will be incremented.
For example:
1st time => ABC12345
2nd time => ABC12346
and so on.
Create FUNCTION instead of Stored Procedure
CREATE FUNCTION USF_GenerateNewID() RETURNS VARCHAR(10)
AS
BEGIN
DECLARE #Prefix VARCHAR(3) = 'ABC'
DECLARE #ID VARCHAR(10)
SET #ID = (SELECT TOP 1 ID FROM <TABLE> ORDER BY ID DESC)
SET #ID = #Prefix + CAST((CAST(REPLACE(#ID,#Prefix,'') AS INT) + 1) AS VARCHAR(10))
RETURN #ID
END