score:2
Accepted answer
ALTER PROCEDURE dbo.EditUserInfo
(
@FirstName NVARCHAR(100),
@LastName NVARCHAR(200),
@UserName NVARCHAR(100),
@Password BINARY = NULL
)
AS BEGIN
SET NOCOUNT ON
UPDATE dbo.UserAcount
SET FirstName = @FirstName,
LastName = @LastName,
Password = ISNULL(@Password, Password)
WHERE UserName = @UserName
END
score:3
You can just add "= NULL" after @password parameter.
alter procedure EditUserInfo
(@FirstName nvarchar(100),
@LastName nvarchar(200),
@UserName nvarchar(100),
@Password binary = NULL
)
as
begin
if (@Password IS NULL)
BEGIN
UPDATE UserAcount
SET
FirstName = @FirstName ,
LastName = @LastName
where UserName = @UserName
END
ELSE
BEGIN
UPDATE UserAcount
SET
FirstName = @FirstName ,
LastName = @LastName,
[Password] = @Password
where UserName = @UserName
END
end
More questions
- What is wrong with this SQL Server query division calculation?
- This is a inefficiently written nested cursor. Can you replace it with a more efficient query that and explain what was wrong about mine?
- What is wrong with this SQL Server query
- What is wrong in my tsql query?
- SQL query can't get the code right in C# and I don´t know what is wrong
- i am getting an error - Subquery returned more than 1 value. What is wrong with my query
- When no 'Order by' is specified, what order does a query choose for your record set?
- TSQL - Sum a union query
- TSQL query to find un-used stored procedures
- Entity Framework 5 wrong data type in query
- tSQL NOT IN Query
- What is wrong with my Try Catch in T-SQL?
- What is wrong with Cursors?
- What Happens To a Query If It Times Out?
- What this query does to create comma delimited list SQL Server?
- SSRS: field shows correct in query but wrong in report preview
- What do the different colored bars in the query editor menu mean in SSMS?
- TSQL query returning double the rows with inner join of same table twice
- NHibernate uses wrong column type for LINQ contains query (varchar to nvarchar)
- What is the limitation in the length of an SqlCommand query
- Simple dynamic TSQL query syntax
- CASE statement in where clause in tsql query
- What does database query and insert speed depend on?
- what is the equivalent query in mysql?
- In SQL Server, what is the difference between a user query and a system query?
- What indices should be created to optimize sql query with multiple OR conditions
- What is the best way to compare 2 variants of a SQL query for performance?
- SQL Server: Find out what row caused the TSQL to fail (SSIS)
- What is the difference between ad hoc and prepared query in sql server plan cache?
- How do I find which indexes are being used and what query is using the index?
More questions with similar tag
- Return string with dynamic SQL
- SSIS - How to Identify which package a row in the log table is referring to?
- Why should I use int instead of a byte or short in C#
- SQL Server Transpose (maybe pivot?) multiple rows into one column
- Prepared statement in if else
- Are there any free tools to generate 'INSERT INTO' scripts in MS SQL Server?
- Why we need a primary key?
- How to display data from two tables in a SQL Server database in a gridview?
- Unnecessary conversion to bigint
- How to create table from stored procedure return?
- SQL Server 2012 CPU usage spikes to 100%
- C# - DataTable Out of Memory exception in application to catch SQL Server "INSERT" events
- Oracle SQL Developer 2.1 - Filter not working when using JTDS extension (v1.5 still working)
- Unicode when upgrade to IIS 7
- Create recursive scalar function in SQL
- Can I pass an IQueryable<> to a table valued function?
- Where can I configure "the default server setting"?
- How can I use an INNER JOIN in conjunction with a GROUP BY clause?
- How to change timeout for connection_instance.Open() command?
- inserting into A errors because of a foreign key contraint issue
- Is hierarchyid suitable for large trees with frequent insertions of leaf nodes?
- Grant execute permission for a user on all stored procedures in database?
- Date format date-month-year
- Hiding empty values in SSRS report
- A suspended select Query when called by C# EF core, MSSQL management studio executes the query just fine. Why?
- SQL Server : matching records from 2 tables with sorting
- How to Export an Excel file (.xlsx) format using SQL Server
- EF Core 3.1 creates duplicate column with '1' in name when defining Principal Key relationship between entities
- LINQPad 6 connecting to SQL Server 2019 Docker got the error when pre-login handshake
- Getting peak hourly KW for each month and showing the year, month, day, and hour it occurred for past 10 years?
Source:
stackoverflow.com