how can i insert a query result in a temp table in sql server?
140808
Try this...\nINSERT INTO #temp1 \nselect * \nfrom abc\nwhere\n( select x,y,z,\n  sum(case when a1 = z1 \nthen cast(a1 as float)* (-1) \nelse(cast a1 as float)) as Units\nfrom\nxyz\ngroup by \nx,y,z\nsum(case when a1 = z1 \nthen cast(a1 as float)* (-1) \nelse(cast a1 as float))>0\norder by \nx,y\n)
335757
Can you post any of the code you are trying to do? Im not sure I understand completely what you are trying to accomplish. So you have 266 records in a table and you are trying to do an update on any given record? What is the SQL you are trying to run to do it?\n\nAssuming you have an id field for the 266 records, you just need to do something like "update tablename set field1 = 'blah', field2 = 'somethingelse' where id = #ofidfield". I am assuming you have the html form set up so that the submit page has the uddate query that will probably need the ID field # passed in as a form variable or passed on the URL.\n\nSo when you are outputting the detail records, are you looping through the recordset to create the update link that goes to the update page? So that every detail record has a link to update some information and that link has a distinct ID in it? And have you output the ID you are trying to use before the SQL update query is run to make sure you are using the right value? I guess what I am getting at is it the update query itself that isnt working or are you not getting the right value to that query (but it actually works even though not updating the right record).\n\nSo two things to check. Have you verified that the 32 is actually being passed in the URL? Then have you checked the update statement to make sure it is using that URL variable in the where clause so it knows what record to update? Also, are you on classic asp or aspx?
292214
Once a new UserConnection object has been inserted into the project, you can add new Query objects to it. These query objects can be either stored procedure calls or user-defined SQL statements. Each query object defined at design-time will automatically be available as a method of the new UserConnection class.\n\nTo add a Query object, click the leftmost button on the toolbar. The new Query object is added hierarchically below the UserConnection object, and its Properties Window appears.\n\nSelecting Stored Procedures\nSelect Insert Stored Procedure to view the available stored procedures on the database. The UserConnection designer attempts to establish a connection to the database, using the connection properties you entered. If successful, it enumerates the available stored procedures on the database, allowing you to select one to define the Query object:\n\nQuery Properties dialog box\n\n\n\nInserting User-Defined Queries\nChoose Based on User-Defined SQL to create a local query against the remote database. This enables the SQL property box, into which you enter SQL statements to define your query.\n\nAlternatively, you can click the Build button, which opens the MS-Query query design tool. MS-Query provides a visual interface that allows you to drag and drop database tables and fields, define conditions and set relationships to define the query. When you exit from MS-Query, your visually-designed query is automatically translated into SQL code and inserted into the User-Defined SQL property box.\n\nFor More Information   For more information about using the MS-Query query builder, see MSQry32.hlp which is installed in the &#92;Program Files&#92;Common Files&#92;Microsoft Shared&#92;vba directory.\n\nSetting Other Query Properties\nIn addition to the defining properties discussed above, the Query Property Page has two additional tabs for defining Parameters and advanced properties.\n\nThe Parameters tab on the query property page allows the developer to adjust properties for each parameter in the current query.\n\nParameters properties\n\n\n\nThe parameters shown in the Parameters list box are determined automatically from the query source, and cannot be changed here. Parameters are generated for each parameter marker in the SQL statement for the query (or call statement for stored procedures). Parameter markers are designated by a "?" in accordance with the ODBC specification. For example, the following query would contain two parameters:\n\nSELECT * FROM authors WHERE state = ? AND zip = ?\n\nThe parameter properties that can be changed here are the Name, Direction, ODBC Binding Data Type, and Visual Basic Data Type.\n\nThe Name property can be changed to allow your Visual Basic code to recognize the parameter by a familiar sounding name, if its actual name is complex or not intuitive.\n\nSetting the Direction of a parameter may be necessary for some ODBC databases for which the driver is not capable of determining the direction (input, input/output, or return values). The same is true for the data types, and you may wish to override the default type conversion into Visual Basic data types for use with your code.\n\nAdvanced Query Properties\nThe Advanced tab of the Query Properties page allows for fine-tuning the query by setting limits and thresholds.\n\nAdvanced properties\n\n\n\nThe Call Syntax text box lets you change the call syntax that RDO will use to call the stored procedure. This can be edited to adjust the number of parameters and presence of the return value. Editing the call syntax is an advanced operation and should only be done by developers who understand the ramifications.\n\nUsing the UserConnection Object in Your Code\nYou can insert the UserConnection object into your Visual Basic code just as you would with any class, by creating an object variable and instantiating it with a new instance of the UserConnection class you have defined. For example:\n\nOption Explicit\nPrivate MyConnect As M
241790
C# is commonly used with SQL Server. Using this you simply need to add a reference at the top of your code:\nusing System.Data.SqlClient;\n\nThen use a SqlConnection, SqlCommand, and maybe a SqlDataReader. Set the connection up to reference your DB then create an SQL statement and execute the command. Then the DataReader will allow you to see each part.\nGood Luck!
870873
Well the easiest way is to use a straight out SQL method in access. Its not that a SQL method is hard but is just how you access the information in a table. Below is a link to a page which shows you a great straight forward example of using a few nested select statements or if you want to create an intermediate table to hold the results, that example is there too.\n\nHope this doesn't confuse you too much, but really if you take a look at it, you will find it makes sense. Just read it out loud.\n\nGood luck!
135369
http://www.microsoft.com/technet/prodtechnol/sql/2005/learning/default.mspx
54440
hi , you dont need cursor \ntry this:\n\n-----------------------------------------------\n\nCREATE PROCEDURE test_sp\n\n@username1char(10),\n@username2char(10)\n\nAS\n\nDECLARE \n\n@UserTempTableTABLE ([ID] char(10),\n [USERNAME] char(10),\n [NAME] char(10),\n [ADDRESS] char(10))\n\nINSERT INTO @UserTempTable\nSELECT[ID],\n[USERNAME],\n[NAME] ,\n[ADDRESS]\nFROM    Table1\nWHERE[USERNAME] = @username1\n\nINSERT INTO @UserTempTable\nSELECT[ID],\n[USERNAME],\n[NAME] ,\n[ADDRESS]\nFROM    Table2\nWHERE[USERNAME] = @username2\n\n\nSELECT [ID],\n[USERNAME],\n[NAME] ,\n[ADDRESS]\nFROM@UserTempTable\nGO\n\n-----------------------------------------------
10408
for this u can do one thing thatu will go database menu and click show sql query and add where\n 'Field name ' = today or now as per as ur requrement.
33262
Yes. Each column should have a condition and mutiple values can be given in IN operator.\n\nFor ex The above one can be written like this\n\nSELECT *\nFROM TABLE_NAME\nWHERE COLUMN1 IN (col1val1,col1val2)\nAND COLUMN2 IN (col2val1,col2val2)\nAND  COLUMN3 IN (col3val1,col3val2,col3val3)
1105416
I would never use a column name with a parenthesis in it, so I think you should change that first.\n\nJust call the column name instead....like select 1 from table etc...if its in column 1.
180876
no idea how in your language, but....\n\nin SQL server there is an execute() function that will execute the script, maybe there is one in your language:\n\ndeclare @SQL varchar(2000)\ndeclare @mytable varchar(20)\nset @mytable = "TheTable" \nset @SQL = "Select column from " + @mytable \nexecute (@SQL)\n\nis equivalent to: \nSELECT column from TheTable\n\nthis is sometimes refered to as dynamic SQL since it is not known until runtime
687215
Select NAME THE FIELD AND CONDITION\nFrom NAME THE TABLE\n\nUNION (This is the operator to combine tables in SQL)\n\nSelect NAME THE FIELD AND CONDITION\nFrom NAME THE TABLE;
312052
You could use "select * from table_name where char_field_name like '%'".\n\nBut it would be better to remove the where clause, as this will save up some system resource during the SQL execution.
901685
Move your query and your result to the page where you are going to use the result.\n\nconn.php:\n<?\n$hostname="dbase.sample.net";\n$username="johndoe";\n$password="acem";\n$dbname="dbse1";\nmysql_connect($hostname, $username, $password) or die("Unable to connect to database! Please try again later.");\nmysql_select_db($dbname);\n?>\n\ntest.php:\n<?\n$require_once('conn.php') or die('cannot include db connection script');\n$sql = "SELECT * FROM userstore";\n$rs = mysql_query($sql) or die('cannot get resultset; '.mysql_error());\necho "<table>";\nwhile($row = mysql_fetch_array($rs)) {\necho "<tr><td>$row[userid]</td> <td>$row[first name]</td> <td>$row[last name]</td></tr>;\n}\necho "</table>";\n?>\n\nAlso, a quick note: MySQL column names should never contain spaces and should not contain anything other than numbers and letters. Also, you should never name a column with a MySQL reserved word. See links below.
1100890
you should use an sql connection object from the component toolbar n make a connected architecture.. and then drag n drop an sql command object . in that object's property set type = stored procedure and then proceed. it's as simple as that in visual studio..\nin query builder u'll get the type as : create procedure <> as.... GO.\nthen in ur code for d form write:\nSqlCommand cmd = new SqlCommand (<proc.name>, <connection name>);\ncmd.CommandType=CommandType.StoredProcedure;\ncmd.Parameters.Add( new SqlParameter("@<pname>",<type>,value,<col name>));\ncmd.ExecuteNonQuery();\nhope thiswill work for u?
53286
Replace "thetable" below with the name of your table...\n\nselect count(0)\nfrom syscolumns\nwhere id = (\nselect id from sysobjects\nwhere name='thetable'\n)\n;
992198
To sum a column, use:\nselect sum(the_column) from the_table