If you want to do it this way then this is the syntax you’re after;
IF EXISTS (SELECT * FROM tblGLUserAccess WHERE GLUserName ='xxxxxxxx') BEGIN SELECT 1 END ELSE BEGIN SELECT 2 END
You don’t strictly need the BEGIN..END
statements but it’s probably best to get into that habit from the beginning.
Related Posts:
- How do I perform an IF…THEN in an SQL SELECT?
- Search text in stored procedure in SQL Server
- What is a stored procedure?
- Inserting multiple rows in a single SQL query? [duplicate]
- SQL query to get the employee name and their manager name from the same table
- Must declare the scalar variable
- T-SQL split string
- Must declare the scalar variable
- The SQL OVER() clause – when and why is it useful?
- Update multiple columns in SQL
- SQL Query with SUM with Group By
- SQL update from one Table to another based on a ID match
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- How to drop all tables from a database with one SQL query?
- SQL Server : Arithmetic overflow error converting expression to data type int
- How to calculate percentage with a SQL statement
- Query comparing dates in SQL
- What is the meaning of the prefix N in T-SQL statements and when should I use it?
- Query error with ambiguous column name in SQL
- How to drop all tables from a database with one SQL query?
- How to find sum of multiple columns in a table in SQL Server 2005?
- Conversion failed when converting from a character string to uniqueidentifier – Two GUIDs
- How can I delete using INNER JOIN with SQL Server?
- Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query
- SQL Server Insert if not exists
- CREATE TABLE IF NOT EXISTS equivalent in SQL Server
- SQL Server: Invalid Column Name
- How to group by month from Date field using sql
- How can I get column names from a table in SQL Server?
- Is there a combination of “LIKE” and “IN” in SQL?
- SQL Server IF NOT EXISTS Usage?
- Arithmetic overflow error converting expression to data type datetime. (while displaying date time..)
- How to format a numeric column as phone number in SQL
- SQL – WHERE (X, Y) IN (A, B)
- sql query to return differences between two tables
- SQL: IF clause within WHERE clause
- How to select the last record of a table in SQL?
- SQL- Ignore case while searching for a string
- Append table to an existing one: SQL Server
- SQL Server – An expression of non-boolean type specified in a context where a condition is expected, near ‘RETURN’
- Using Excel VBA to run SQL query
- What is tableName.* in SQL
- What do Clustered and Non-Clustered index actually mean?
- How do I UPDATE from a SELECT in SQL Server?
- SQL query to select dates between two dates
- NOT IN vs NOT EXISTS
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- How do I escape a single quote in SQL Server?
- T-SQL split string based on delimiter
- Data source name not found, and no default driver specified
- Optimistic vs. Pessimistic locking
- Column name or number of supplied values does not match table definition
- Can a foreign key be NULL and/or duplicate?
- When to use SELECT … FOR UPDATE?
- Difference between JOIN and INNER JOIN
- The target principal name is incorrect. Cannot generate SSPI context
- BCP error “Unable to open BCP host data-file”
- “CASE” statement within “WHERE” clause in SQL Server 2008
- What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?
- In SQL Server, what does “SET ANSI_NULLS ON” mean?
- Operand type clash: int is incompatible with date + The INSERT statement conflicted with the FOREIGN KEY constraint
- SQL Server WITH statement
- DateTime2 vs DateTime in SQL Server
- Difference between numeric, float and decimal in SQL Server
- SQL Server reports ‘Invalid column name’, but the column is present and the query works through management studio
- What is the equivalent of ‘describe table’ in SQL Server?
- How do I query for all dates greater than a certain date in SQL Server?
- Add a column with a default value to an existing table in SQL Server
- Remote table-Valued Function Calls are not allowed
- How to create temp table using Create statement in SQL Server?
- MS SQL compare dates?
- ClassNotFoundException – com.microsoft.jdbc.sqlserver.SQLServerDriver
- The backend version is not supported to design database diagrams or tables
- Determine ROW that caused “unexpected end of file” error in BULK INSERT?
- The SELECT permission was denied on the object ‘Users’, database ‘XXX’, schema ‘dbo’
- How do you open an SDF file (SQL Server Compact Edition)?
- Get size of all tables in database
- Using RegEx in SQL Server
- Conversion failed when converting the varchar value ‘simple, ‘ to data type int
- Must declare the scalar variable
- Exclude a column using SELECT * [except columnA] FROM tableA?
- ORA-06502: PL/SQL: numeric or value error: character string buffer too small
- What is the difference between a stored procedure and a view?
- Why is SQL server throwing this error: Cannot insert the value NULL into column ‘id’?
- Bulk load data conversion error (truncation)
- ‘Microsoft.ACE.OLEDB.16.0’ provider is not registered on the local machine.
- How do I fix the multiple-step OLE DB operation errors in SSIS?
- SQL Server: Error converting data type nvarchar to numeric
- How do I format a number with commas in T-SQL?
- ‘CREATE PROCEDURE’ must be the only statement in the batch (Erro)
- To add server using sp_addlinkedserver
- How to connect to a local database in SQL Server Management Studio?
- The server principal is not able to access the database under the current security context in SQL Server MS 2012
- Solutions for INSERT OR UPDATE on SQL Server
- What are named pipes?
- SHOWPLAN permission denied in database ‘tempdb’. in sql server 2008
- “select * into table” Will it work for inserting data into existing table
- INSERT VALUES WHERE NOT EXISTS
- CASE IN statement with multiple values
- How to implement LIMIT with SQL Server? [duplicate]