C# .NET - sql server simple query

Asked By sara asa on 04-May-12 03:28 PM
hi
i have a table as users with this field(id ,name,family,age)mt id and age  are int and name and family nvarchar(50)
i tried with design query in editory select name and family with parameter age..under window it show me as this

@age int

SELECT


name, family, age

FROM users

WHERE (age = @age)


ofcourse i set @age int  with my hand not editor but it show me syntax error
like this

Msg 137, Level 15, State 2, Line 3

Must declare the scalar variable "@age".


ofcourse i decalre id as int and auto number age as int and name and family as nvarchar(50)

how can i solve thissimple query error..i guess ididnt make any mistake...plz help me..i guess it should be more simple in editor but it was n't..

ty

Robbe Morris replied to sara asa on 04-May-12 06:01 PM
declare @age int

set @age = 18

select *
  from tableA
 where age = @age
Venkat K replied to sara asa on 04-May-12 11:15 PM
You need to use the DECLARE Keyword when declaring variables:
Modify the code as below:

DECLARE @age INT
SELECT Name, Family, Age FROM Users WITH(NOLOCK) WHERE age=@age

Thanks

sara asa replied to Robbe Morris on 05-May-12 06:40 AM
ty
sara asa replied to Venkat K on 05-May-12 06:41 AM
ty
help
We used to have automatic scheduled task to backup the LCS Standard edition (running on SQL Desktop Edition). However, it looks like it hasn't been backing up the database for run the command directly, i get the following: - -- -- -- -- -- -- -- -- -- -- C: \ > "C: \ Program Files \ Microsoft LC 2005 \ Server \ Support \ dbbackup.exe" / backupfile:"C: \ LC \ LC Backup" Connecting to SQL Server. . . Performing backup. . . Error: Failed to backup database. SQL Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'mirror_count'. [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid
Is there a way to see the memory (RAM) usage by an SQL Server instance, and get that value by executing a statement in Query Analyzer? SQL Server 6
I have been finding that I am having trouble with the Crystal Reports Server XI installation failing when it is dealing with SQL. So, as a thought and in case there was something wrong with my SQL portion of the isntall. I thought ok, I will try installing the actual MSDE application direct from Microsoft. So, I downloaded the MSDE for SQL 2000 (which is msde2000a.exe), set my switches and off to the races. It quit
Does Microsoft still support SQL server 2000? SQL Server New Users Discussions SQL Server (1) SQL Server Books Online (1) SQL
Hi! I have two SQL Server 2008 Std (Sql Server A and Sql Server B
Connection failed: SQLState: '28000' SQL Server Error: 18452 [Microsoft][ODBC SQL Server Driver][SQL Server] Login failed for user 'sa'. Reason
Can i use SQL Server 2005 Express Management studio to connect to a SQL Server 2000 Instance. SQL Server Tools
How do you get sql server agent? SQL Server Programming Discussions SQL Server 2005 (1) SQL Server 2000 (1) RLF (1
Hi, I have created a database in SQL Server 2008, with compatibility level of
Hi! Do you know any free MS SQL Server database hosting service? SQL Server Discussions SQL Express (1) SQL Server (1) Where can I