|
Hello,
I'm using sql server and I want to use a parameter in an IN clause in the command.
e.g.
select * from tableX where ID in @test
(The "expanded" version would look like: select * from tableX where ID in ('ID1','ID2','ID3') )
No matter how I declare or fill that variable I don't succeed.
Can anybody help please?
Thank you,
Wim
|
|
|
|
|
|
Thanks for your quick reply, but I don't want to use a stored procedure.
Just a simple statement with a sql variable.
declare @test varchar(600)
select @test = <list of="" id's="" in="" some="" form="">and do the select statement like this:
select * from tableX where ID in @test
(The "expanded" version would look like: select * from tableX where ID in ('ID1','ID2','ID3') )
|
|
|
|
|
@test is a variable replaced at query execution. Using your 'expanded' example, the resultant query would be looking for all rows where ID = "('ID1','ID2','ID3')". The IN would result to equal because there is only one element in the clause (@test).
SQL variables can only replace one element, not a list of more than one. You can get around this with dynamic SQL generation which uses your variable to build a new SQL string but, you indicate you don't want to use a Stored Proc.
Solution: Drop the variable and rewrite your code to build the full statement with a comma deliminated IN clause.
|
|
|
|
|
Ok, thanks for your clear reply.
|
|
|
|
|
http://www.projectdmx.com/tsql/sqlarrays.aspx
The link above gives you three examples of how you could do this.
|
|
|
|
|
Hi all,
I have a problem in a project using MySQL/C# which is: i have some users and news board such that each user has his own news (which is a huge number) and the news board is refreshed each 30 seconds for each user. so for example, i have to go to DB every 30 seconds to return about 700 records (news) for each user which makes the system very slow. these news are divided among pages (each page have 20 news) so now i want to know if there is a method to reduce number of records returned or something in paging or something to refresh current page only or ... ? i don't know. can anyone help?
Thank you
|
|
|
|
|
|
What is the TEXT datatype? How should it be used? Is it good or bad?
I have to save a long text to the database. I don't know the size that should be saved. Is it better to use the TEXT dataType or the VARCHAR datatype.
|
|
|
|
|
quiteSmart wrote: What is the TEXT datatype?
A data type for storing text - up to 2Gb
quiteSmart wrote: How should it be used?
When you have large amounts of text to store
quiteSmart wrote: Is it good or bad?
Like anything it depends. If you pull the TEXT data out on each query whether it is required or not it is bad. If you are careful it is very good.
quiteSmart wrote: I have to save a long text to the database. I don't know the size that should be saved. Is it better to use the TEXT dataType or the VARCHAR datatype.
If the text data is going to be over 8K a TEXT data type is your only option.
|
|
|
|
|
i have read an article that says that i can use the VARCHAR to arround 2 billion characters. They say in this article that i should write the dataType like this:
VARCHAR(max)
i am trying it but it doesn't work.
the link for the article is this:here
One more question concerning the TEXT dataType,
Does it have any problems concerning the storage capacity? or Is it like the varchar? meaning that it only takes the space it needs for saving not more?
Thanks for the reply
|
|
|
|
|
Which version of SQL Server are you using?
|
|
|
|
|
andyharman wrote: Which version of SQL Server are you using?
Microsoft SQL Server Management Studio Express 9.00.2047.00
|
|
|
|
|
quiteSmart wrote: Microsoft SQL Server Management Studio Express 9.00.2047.00
That is the IDE, not the version of the database engine. If you are using this IDE and it is the only version of SQL Server you have installed then you are using SQL Server 2005
|
|
|
|
|
|
I don't have access to SQL-Server 2005 from this machine, but you should be able to create tables like:
create table MyTable(
Id int identity(1,1) not null,
MyBigColumn varchar(max) null
) I believe that Microsoft are recommending use of "varchar(max)" instead of the "text" data-type.
Regards
Andy
|
|
|
|
|
andyharman wrote: MyBigColumn varchar(max) null
I read on MSDN that i can do this, but when trying it; it doesn't work
i don't have any clue why that is happening
|
|
|
|
|
What error message do you get?
|
|
|
|
|
andyharman wrote: What error message do you get?
Syntax Error newr 'max'
|
|
|
|
|
quiteSmart wrote: i have read an article that says that i can use the VARCHAR to arround 2 billion characters.
If you are using SQL Server 2005 (I forgot about that - I'm not yet using SQL Server 2005)
|
|
|
|
|
BLOB data is stored separately from the record in the underlying data structure by the RDBMS
File Not Found
|
|
|
|
|
Respected sir,
I have some of the questions related to sql queries
1.what is the sql server query for having the 3rd max salary record from the following table
EmpId Empname EmpSal
1 Joseph 1000
2 rahul 299
3 Rahim 4000
4 John 350
5 kate 2000
2.what is the sql server query for arraning the records with latest date for the following table
EmpId Empname EmpSal Date
1 Joseph 1000 21may2005
2 rahul 299 12 june2004
3 Rahim 4000 3may2006
4 John 350 5april2001
5 kate 2000 8june1998
3.how to sort the particular coloumn with out affecting to other coloums like
Empnam empSal
Joseph 1000
rahul 299
Rahim 4000
John 350
kate 2000
the above table has to be translated as given below in which only the salary is sorted in descending order with out disturbing empnames
Empname Empsal
joseph 4000
rahul 2000
rahim 1000
john 350
kate 299
4.In stored procedures how to jump to required line,
for example we have 1 stored procedure in which it contains 20 lines of code,but during accessing if we want to execute 8th line directly jumping from 2line of code.how to make it possible
please suggest me
Thanking you in anticipation
|
|
|
|
|
MD12 wrote: what is the sql server query for having the 3rd max salary record from the following table
SELECT TOP 1 FROM (SELECT TOP 3 FROM MyTable ORDER BY Salary ASC) ORDER BY Salary DESC
MD12 wrote: what is the sql server query for arraning the records with latest date for the following table
It depends what you mean by "arraging the records with the latest date"
SELECT * FROM MyTable ORDER BY SomeDateColumn
MD12 wrote: 3.how to sort the particular coloumn with out affecting to other coloums like
I have never come across a situation where that was useful.
MD12 wrote: 4.In stored procedures how to jump to required line
Use GOTO - or better would be to create a proper conditional structure with an IF block.
|
|
|
|
|
I have a the following table structure
t_entity
entity_id
connect_date
disconnect_date
t_entity_info
entity_id
property_name
value
Let's say I have the following data in the tables
t_entity
1 | 1/1/2005 | 12/1/2005
2 | 1/1/2006 | 12/1/2006
t_entity_info
1 | application | ds3
1 | subapplicaiton | wan
2 | application | voice
2 | subapplicaiton | phone
I want the following results with one query (using Oracle)
1 | 1/1/2005 | 12/1/2005 | ds3 | wan
2 | 1/1/2006 | 12/1/2006 | voice | phone
Anyone got any ideas? Thanks in advance.
Mike Lasseter
|
|
|
|
|
Hi all .
I wanna know ... :
1. What is the difference between Sqlserver2000 and SqlServer2005 ??
2. Which one is more useful ?
3. Which one works better and is more compatible with Asp.net2003 ?
Thank you very Much.
|
|
|
|