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 have a query like this:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[User_SelectByLoginID]
#LoginID nvarChar(4)
as
SELECT dbo.[User].*
FROM dbo.[User]
WHERE LoginID=#LoginID
And data in the User table:
LoginID ='1111' | Name ='abc' | Email = 'abc#yahoo.com'
when I executed this query and typed in '1111111', it returned the record:
1111 abc abc#yahoo.com
it is ridiculous when I entered the wrong LoginID and still got the data.
P/S: I set LoginID nvarchar(4)
Can someone explain for me? And how to make it right?
If you set #LoginID to nvarchar(4) it will truncate to that size so really you are passing in 1111 and not 11111111.
SQL Server silently truncates your value passed to stored procedure, so even though you pass value '1111111', it is cut off to the declared length (4) so in your stored procedure there is a value '1111'.
So you should declare your parameter #LoginID to the same size which has your column LoginID in User table
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am using sql server and i want to increase size of my column but it gives exception
-- increase size of email type
ALTER TABLE [dbo].[AM_email_content]
ALTER COLUMN [email_type] VARCHAR(100);
There is no issue in your Alter statement. It should work. Select your entire statement and then execute it in SSMS.
ALTER TABLE [dbo].[AM_email_content] ALTER COLUMN [email_type] VARCHAR(100);
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 6 years ago.
Improve this question
I'm doing a couple of tests regarding speed in SQL Server. To do it I have this simple query:
DECLARE #Time1 Date;
DECLARE #Time2 Date;
Set #Time1 = GETDATE();
-- Stuff happening
Set #Time2 = GETDATE();
Now I want to check the values of these properties (Time1 and Time2). I tried doing a SELECT #Time1, Time2 but kept getting errors, so how can I check these values?
EDIT: as I mentioned to the accepted answer author, it was probably some syntax error that was eluding me from using a simple SELECT.
As for the fact the question is On Hold, I really don't see why as it seems a simple question to me. I created #parameters and set a value to them, then I want to check these values.
"Doing a SELECT is not possible" - Who told you this?
DECLARE #Time1 DateTime;
DECLARE #Time2 DateTime;
Set #Time1 = GETDATE();
-- Stuff happening
Set #Time2 = GETDATE();
SELECT
#Time1
,#Time2
I've used this when analysing a large stored procedure, I put some datetime parameters at key points within the stored proc using getdate() and inserted them into an audit table at the end of the procedure. It was really handy for determining which part of the live stored procedure was going slowly for users.
First, perhaps, it is nessecarry to declare the #TimeX as TIME values - not as DATE ....
and than you con use PRINT
Print #Time1
Print #Time2
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 6 years ago.
Improve this question
Please help me I am using SQL Server. I want to create a backup to my device after action EXECUTION text execution in mvc C#.
Suppose you have BackUp method in HomeController, then execute the follwoing store procedure.
_dbcontext.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, #"EXEC [dbo].[spBackUpDatabases]");
and spBackUpDatabases store procedure is like
USE [TestAppDbContext]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spBackUpDatabases]
AS
BEGIN
SET NOCOUNT ON;
-- backup database TestAppDbContext to disk='D:/TestAppDb/test.bak'
exec( 'backup database TestAppDbContext to disk = N''D:/TestAppDb/test.bak'' with format, init;' );
END
I think this help u.
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 6 years ago.
Improve this question
How to call one stored procedure from another stored procedure and when I do that. Then it is not updating in Crystal Report field explorer.
This is my code:
SP1
ALTER PROCEDURE [dbo].[GetSpecialJournalInfoByJVID]
(#JvID numeric,#BusinessID numeric)
AS
BEGIN
SET NOCOUNT ON;
SELECT *
FROM JV
WHERE jvID = #JvID AND BusinessID = #BusinessID
END
SP2
ALTER PROCEDURE [dbo].[USP_GetSpecificAccountLedger]
#JvID numeric(18,0),
-- Add the parameters for the stored procedure here
#ParamDate1 datetime,
#ParamDate2 datetime,
#ParamBusinessID numeric(18,0),
#ParamAccountID numeric(18,0),
#ParamCurrentCurrencyRate decimal(18,10) =1
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT *
FROM JV
WHERE jvID = #JvID
-- Insert statements for procedure here
SELECT
COA.ACCOUNTID, COA.ACCOUNTNAME, COA.GLCODE,
COA.DESCRIPTION AS ACCOUNTDESCRIPTION,
COA.ISBANKACCOUNT, COA.BANKACCOUNTNO,
COA.REFACCOUNT, FIXED,
ISNULL(OPBAL.OPENINGBALANCE, 0) OPENINGBALANCE,
ISNULL(CURBAL.DR_CUR_BAL, 0) DR_CUR_BAL,
ISNULL(CURBAL.CR_CUR_BAL, 0) CR_CUR_BAL,
J.TRNDATE, J.TRNDESCRIPTION, TRNTYPE,
I need help, I googled it a lot but didn't got any solution
thanks in advance...
You can call a stored procedure by using the EXEC command. However, it might be better to use SQL Server user-defined function.
Please see: https://technet.microsoft.com/en-us/library/aa175085(v=sql.80).aspx
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am using 2008 R2 ,I want to set output of "Select Colname from tablename" to one veriable ie. #resultvar ,so further I can use it in stored procedure.
If you are only interested in a single value, it is as simple as:
DECLARE #resultVar nvarchar(50) -- or whatever
SELECT #resultVar = Colname FROM tablename -- with appropriate filtering
If you're needing to get this out from a stored procedure, then you need to look into OUTPUT parameters:
CREATE procedure MyProcedure
#resultVar nvarchar(50) OUTPUT
AS
SELECT #resultVar = Colname FROM tablename -- with appropriate filtering
If you're using SQL to run the procedure, you can then use:
EXEC MyProcedure #var OUTPUT
Obviously, if you're using a framework such as Entity Framework, then you need to use whatever that framework provides; but, that's a totally separate question.
Be aware that if multiple rows come back from tablename, you will only get the value from the first row. If it is more complex than this, please expand the original question.
You can use a simple code like this:
DECLARE #resultvar AS VARCHAR(64) --or any other type you need
SELECT #resultvar = ColName FROM TableName WHERE --filter on table
PRINT #resultvar