var allRecords = new array();
<%While (NOT rs_yours.EOF)%>
allrecords[count]="<%= rs_yours.Fields.Item("foo1").Value %>"
Hope this helps 🙂
Today I just got went though this, this helps you to execute a string in SQL. This is how you can execute a string in SQL,
[code]Declare @query Varchar(500)
Set @query = ‘Select * From Employees’
Another alternate option is as follows,
[code]EXEC (‘USE AdventureWorks; SELECT EmployeeID, Title FROM HumanResources.Employee;’)[/code]
This way you can execute a string in SQL.
This is extremely helpful when you need to add the Where clause based on some criteria. You can have your query in a string and based on that criteria you can append the clause in that string and finally execute the string at the end. This works perfectly.
However this does not work if you want to execute the query and get the result in the Dataset in your .Net application. For that you need to create a #Temp table execute the string and get the result in the #Temp table and then fire the select again on your #Temp table.
Note: Don’t forget to get the brackets ( & ) around your query else SQL will throw an error, Unrecognized stored procedure.
How will you copy table structure using an SQL Query?
This was the question I was asked in one of the inteview, after hearing this I first thought, Is there a way to copy only the table structure. I only knew the query to copy data along with its structure and take backup of tables.And I answered the same.
Later after finishing my interview I went home and googled on this, and was really surprised when I found these two queries.
So thought of sharing this.
Below are the queries which will only copy the table structure.
select * INTO newtable from oldtable where 1=2</code>
select Top 0 * into newtable from [oldtable][/code]
Hope this will help lot of them who are like me 🙂
Often it is required where we need to get the list of tables in our database and the colums of the table with datatype.
Below is the query which will list all tables.
select * from sysobjects where xtype=’U’
Query which will return list of tables with columns and respective datatype.
where table_name in (select name from sysobjects where xtype=’U’)
order by table_name