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
- Selecting COUNT(*) with DISTINCT
- Case in Select Statement
- What do Clustered and Non-Clustered index actually mean?
- Conversion failed when converting date and/or time from character string while inserting datetime
- Self Join to get employee manager name
- How do I UPDATE from a SELECT in SQL Server?
- SQL query to select dates between two dates
- Conversion failed when converting date and/or time from character string while inserting datetime
- When should I use CROSS APPLY over INNER JOIN?
- Insert Data Into Temp Table with Query
- error, string or binary data would be truncated when trying to insert
- How to create Temp table with SELECT * INTO tempTable FROM CTE Query
- NOT IN vs NOT EXISTS
- How can I do an UPDATE statement with JOIN in SQL Server?
- Rename column SQL Server 2008
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- Efficiently convert rows to columns in sql server
- How to delete duplicate rows in SQL Server?
- Nested select statement in SQL Server
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- SQL Query with NOT LIKE IN
- How do I escape a single quote in SQL Server?
- T-SQL split string based on delimiter
- Drop a temporary table if it exists
- How do I escape a single quote in SQL Server?
- How Stuff and ‘For Xml Path’ work in SQL Server?
- Data source name not found, and no default driver specified
- IDENTITY_INSERT is set to OFF – How to turn it ON?
- An attempt was made to access a socket in a way forbidden by its access permissions
- Each GROUP BY expression must contain at least one column that is not an outer reference
- Optimistic vs. Pessimistic locking
- Column name or number of supplied values does not match table definition
- Inserting data into a temporary table
- Can a foreign key be NULL and/or duplicate?
- Why does NULL = NULL evaluate to false in SQL server
- When to use SELECT … FOR UPDATE?
- CREATE VIEW must be the only statement in the batch
- SQL Server FOR EACH Loop
- Difference between JOIN and INNER JOIN
- The target principal name is incorrect. Cannot generate SSPI context
- The EXECUTE permission was denied on the object ‘xxxxxxx’, database ‘zzzzzzz’, schema ‘dbo’
- Best way to do nested case statement logic in SQL Server
- BCP error “Unable to open BCP host data-file”
- How can I clone an SQL Server database on the same server in SQL Server 2008 Express?
- The multi-part identifier could not be bound
- “CASE” statement within “WHERE” clause in SQL Server 2008
- Get day of week in SQL Server 2005/2008
- How to join two tables by multiple columns in SQL?
- What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?
- In SQL Server, what does “SET ANSI_NULLS ON” mean?
- incorrect syntax error CREATE VIEW must be the only statement in the batch
- SQL Server : error converting data type varchar to numeric
- Operand type clash: int is incompatible with date + The INSERT statement conflicted with the FOREIGN KEY constraint
- Keeping it simple and how to do multiple CTE in a query
- Why use a READ UNCOMMITTED isolation level?
- SQL Server WITH statement
- Find all tables containing column with specified name – MS SQL Server
- DateTime2 vs DateTime in SQL Server