|
Not sure exactly what you are trying to do, but if you need to look for a particular value and if you are using datatables you could loop through your column names and in each loop run a datatable.select command, storing the values in an array.
More information would be helpful.
Our developers never release code. Rather, it tends to escape, pillaging the countryside all around.
The Enlightenment Project (paraphrased comment)
GISDevCafe.com
|
|
|
|
|
hi guys
can anyone plz tell me the syntax for the following queries
1.Alter Table name
2.Alter Column name
3.Alter Column dataType
4.Alter Primary/Foreign/Unique constraints of a Column
plz tell queries that work in Sql Server.
these are the queries that i am using for the first two tasks and they don't work
1.
string sql="ALTER TABLE "+comboBox2.Text+" TO "+new_tn;
2.
string sql="ALTER TABLE "+comboBox2.Text+" RENAME COLUMN "+new_tn;
regards
|
|
|
|
|
The syntax for SQL Server 2000 is:
1. EXEC sp_rename 'old_table_name', 'new_table_name'
2. EXEC sp_rename 'table_name.old_column_name', 'new_column_name', 'COLUMN'
3. ALTER TABLE table_name ALTER COLUMN column_name new_data_type
4. Lookup "ALTER TABLE" in "SQL Server Books Online".
Regards
Andy
|
|
|
|
|
thank you
regards
Saira
|
|
|
|
|
I want examples of some complex sql queries.
such as there could be some 2 - 3 tables as Purchase , Order and Order Details etc..
and there would be some 50 questions asked with answers i.e sql queries
pls suggested me some links that would contains above mentioned example.
Thanks in advance
Praveen
|
|
|
|
|
If you have Access of SQL Server 97/2000 installed, I would suggest that you take a look at the stored procedures/queries that are installed as part of the reference database. If you have some variant of SQL Server 2005, the AdventureWorks database is an excellent source of queries to look at.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi, I am learning C# and .NET 2.0. I have so far read two books that touch on ADO and SQL. They are Pro C# 2005 and the .NET 2.0 Platform and Pro .NET 2.0 Windows Forms and Custom Controls in C#. They both confused me more than anything. I want to understand these concepts as a Windows or ASP .NET application programmer. I want to understand how to access databases as well as create one, but don't want to learn enough to become a DBA. I just want to know enough to know what I am doing with them.
For example, I am thinking of writing a client/server Quicken like program. Users can access it to create their own bank accounts, and others can then access the DB to get reports.
So where should I start? Do I get a book on SQL or ADO .NET first? Is there a good book that explains it to a beginner?
Thanks!
|
|
|
|
|
|
Will SQL Server truncate input that is longer than the allotted field automatically or do I need to pre-truncate it? I only ask because some code I've inherited does this and I always thought that it would just drop what didnt fit.
I also know this isnt a good thing necessarily and may never be an issue but it just seems like wasted comp cycles to do this in the application.
Cleako
|
|
|
|
|
I have always been of the opinion that the data should be as clean as possible before it gets sent to the database. As a user, I would prefer to know if my data is being truncated and have the ability to change it if it is. Sometimes a re-wording is preferrable to a truncation.
|
|
|
|
|
The problem in my case is that I am working on a web service so it is up to the sending person to limit the length.
Are you saying, though, that you would rather have the data pre-truncated than to let SQL Server do it?
Cleako
|
|
|
|
|
|
Hi,
I am using fulltext indexing for searching for a list of values in a given text field(which contains description).
For example this is my query.
select * from details where contains(description,'"manager" or "sales manager" or "zonal manager"')
Now I have the second part of the contians in another table. i.e '"manager" or "sales manager" or "zonal manager"' is stored in another table.
But when I am giving select statement in the second part of contains it is giving me an error. How to search for description by taking values from another table with out using loops and in a single query.
If I am using cursors and performing the search it is taking lot of time.How can I speed up?
Regards,
Uma
|
|
|
|
|
I'm not sure i entirely understand your question, but can you not join onto the other table in the query?
|
|
|
|
|
how can we put variable inside the query i put it as
'select '+@name+' =hlp_tTblNm from mhelp with(nolock) where hlp_tAlias='acc2''
but it shows problem
shailendra
|
|
|
|
|
No, this won't work because the result of your varible gets placed inside the query and not the variable reference. If you are going to use a variable inside a dynamic t-sql string that variable must be declared inside the actual t-sql string.
Plus, if you're using your select statement to instantiate the variable @name is probably null. Which means if CONCAT_NULL_YIELDS_NULL is set to the default your entire string will be null.
If you can provide context for what it is you're trying to do we can give a recommendation that will help. Right now there are too many possibilites.
But I will at least take an initial jab and say that you're trying to do something like this:
<br />
DECLARE @Sql VARCHAR(2000)<br />
<br />
SET @Sql = '<br />
DECLARE @name = VARCHAR(50)<br />
SELECT @name = hlp_tTblNm FROM mhelp WITH(NOLOCK) WHERE hlp_tAlias = 'acc2'<br />
<br />
SELECT .... FROM ??? WHERE ??? = @name'<br />
<br />
EXECUTE (@Sql)<br />
|
|
|
|
|
I have to take the value of a column in a variable @name
The below code works fine but i have to take it in another variable @query
but it doesn't works please suggest me the solution
declare @name varchar(50)
declare @query varchar(500)
select @name=hlp_tTblNm from mhelp with(nolock) where hlp_tAlias='acc2'
print @name
problem
*********
declare @name varchar(50)
declare @query varchar(500)
set @query='select '+@name+'=hlp_tTblNm from mhelp with(nolock) where hlp_tAlias='acc2''
print @name
print @query
this code give me error incorrect syntex near acc2
shailendra
|
|
|
|
|
You need to put two quotes in before acc2, e.g. ''acc2''.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I am getting a weird datetime error trying to insert a System.DateTime into a database.
The code i have used is:
cmd.Parameters.Add("@DOB", SqlDbType.DateTime).Value = DOB.Date.ToShortDateString();
where the string returned is 24/11/1972 and also used the format 11/24/1972.
I have also created an SlqDateTime and passed in my System.DateTime object to the constructor then used this code
cmd.Parameters.Add("@DOB", SqlDbType.DateTime).Value = sqlDate;
But every time i catch this exception.
"Conversion failed when converting datetime from character string."
I am pretty confident this is a school boy error so any help would be much appreciated.
Cheers
Dan
|
|
|
|
|
DanB1983 wrote: cmd.Parameters.Add("@DOB", SqlDbType.DateTime).Value = DOB.Date.ToShortDateString();
Try this:
cmd.Parameters.Add("@DOB", SqlDbType.DateTime).Value = DOB.Date;
(I'm assuming that DOB.Date is a System.DateTime object.)
Jon Sagara
I controlled my laughter and simple said "No,I am very busy,so I can't write any code for you". The moment they heard this all the smiling face turned into a sad looking face and one of them farted. So i had to leave the place as soon as possible.
--Mr.Prakash
Blog | Site | Articles
|
|
|
|
|
Hi
I am using C++ and ADO to connect and retrieve data out of a MSSQL database (2005). I have a problem when executing simple queries like "SELECT MyText From MyTable" (whereas MyText would be a VARCHAR). For executing this query I use a record set like this:
RecordSet->Open(...);
if (!RecordSet->EndOfFile) {
_bstr_t result = RecordSet->Fields->GetItem(_T("MyText"))->GetValue();
...
}
After this, the result variable contains in fact a value for MyText in this table. But the problem is that it does not only contain the text of MyText but also many whitespaces behind. That means, that if MyText was e.g. a VARCHAR(100), I get the text of it and behind a sequence of spaces till my _bstr_t gets the length of 100.
Is there any solution to this problem, except for parsing out the spaces behind my string by hand?
|
|
|
|
|
Hi,
I use _variant_t to get the value _variant_t tValue = pRS->GetFields()->GetItem(_T("YouFieldName"))->GetValue(); it works well, if you want to get CString type data, then: tValue.ChangeType(VT_BSTR);CString strValue = tValue.bstrVal;
|
|
|
|
|
Hi,
thanks for your reply. I did a mistake when posting the code in here. In fact I do it exactly the way you do it. But I have still this problem that there are a lot of spaces behind the "real" string. Any other ideas? I don't have a real idea.; it's just very strange...
|
|
|
|
|
Hi,
It's very strange, i use mssql2000+sp4 and not found this trouble.
why didn't you using strValue.trimRight() to trim the space off?
|
|
|
|
|
Yes that's of course a possibility, which means that I parse out the spaces behind the real string by hand. But I wondered if there wasn't any other possibility or if I made something wrong when getting this value from the database. But it seems that I made it correctly... that's just strange...
Anyway thank you
|
|
|
|