473,404 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Update & Select in one?!

Hello,

I am having difficulty finding a way to convert this code into a stored
procedure on SQL Server...Here is the original code


Expand|Select|Wrap|Line Numbers
  1.     IF Request("updflag" & n) = "Y" then 
  2.  
  3.  
  4.                 cmdTemp.CommandText = " SELECT ast.asset_id, " & _ 
  5.                                       " mast.meter_read_due_dt, mast.meter_sort, 
  6. mast.update_flag " & _ 
  7.                                       " From asset ast, meter_asset mast" & _ 
  8.                                       " WHERE (ast.asset_id='" & Request("assetcode" 
  9. & n) & "')" & _ 
  10.                                       " AND   (ast.asset_id = mast.asset_id)" 
  11.  
  12.  
  13.                 cmdTemp.CommandType = adCmdText                                         'Text Command 
  14.                 Set cmdTemp.ActiveConnection = BEConn                           'Set database connection 
  15.                 objRS.Open cmdTemp, , adOpenKeyset, adLockOptimistic 
  16.                 If Not objRS.EOF and Not objRS.BOF then 
  17.                         sAssetCD = objRS.Fields("asset_id").value 
  18.                         dtMeterDate = objRS.Fields("meter_read_due_dt") 
  19.                         objRS.Fields("meter_sort") = Trim(Request("newsort" & n)) 
  20.                         objRs.Fields("update_flag") = "Y" 
  21.                         objRS.Update 

Now I have figured out that you can do if exists (select.....)begin <do update> end

But I need records returned to my ASP code as well. Is this possible?
Oct 13 '06 #1
1 8202
Hello,

I am having difficulty finding a way to convert this code into a stored
procedure on SQL Server...Here is the original code


Expand|Select|Wrap|Line Numbers
  1.     IF Request("updflag" & n) = "Y" then 
  2.  
  3.  
  4.                 cmdTemp.CommandText = " SELECT ast.asset_id, " & _ 
  5.                                       " mast.meter_read_due_dt, mast.meter_sort, 
  6. mast.update_flag " & _ 
  7.                                       " From asset ast, meter_asset mast" & _ 
  8.                                       " WHERE (ast.asset_id='" & Request("assetcode" 
  9. & n) & "')" & _ 
  10.                                       " AND   (ast.asset_id = mast.asset_id)" 
  11.  
  12.  
  13.                 cmdTemp.CommandType = adCmdText                                         'Text Command 
  14.                 Set cmdTemp.ActiveConnection = BEConn                           'Set database connection 
  15.                 objRS.Open cmdTemp, , adOpenKeyset, adLockOptimistic 
  16.                 If Not objRS.EOF and Not objRS.BOF then 
  17.                         sAssetCD = objRS.Fields("asset_id").value 
  18.                         dtMeterDate = objRS.Fields("meter_read_due_dt") 
  19.                         objRS.Fields("meter_sort") = Trim(Request("newsort" & n)) 
  20.                         objRs.Fields("update_flag") = "Y" 
  21.                         objRS.Update 

Now I have figured out that you can do if exists (select.....)begin <do update> end

But I need records returned to my ASP code as well. Is this possible?
Solved...I think anyway!!

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.p_update_asset
  2. @asset_code varchar(20),
  3. @newsort varchar(20),
  4. @assetID varchar(20) OUTPUT,
  5. @duedate datetime OUTPUT,
  6. @update varchar(20) OUTPUT,
  7. @sort varchar(20) OUTPUT
  8. AS
  9.  
  10. DECLARE @rowcount int
  11. DECLARE @ID varchar(20)
  12.  
  13. SELECT @assetID = ast.asset_id, 
  14.        @duedate = mast.meter_read_due_dt, 
  15.        @sort = mast.meter_sort, 
  16.        @update = mast.update_flag 
  17. FROM asset ast, meter_asset mast 
  18. WHERE (ast.asset_id = @asset_code) 
  19.        AND (ast.asset_id = mast.asset_id) 
  20.  
  21. SET @rowcount = @@rowcount
  22. SET @ID = @assetID
  23.  
  24. If @rowcount <> 0
  25. BEGIN
  26.   UPDATE meter_asset
  27.   SET meter_sort = @newsort,
  28.   update_flag = 'Y'
  29.   WHERE (@assetID = @asset_code)
  30.      AND (@assetID = meter_asset.asset_id)
  31. END
  32. GO
Oct 13 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Harald Servat Gelabert | last post by:
Dear news-team I'm using MySQL 4.0.15a (with PHP 4.3.4rc1 and Apache 2.0.47 under FreeBSD). I'm having problems when updating a column of a table (it updates an extra column). As an...
4
by: Smartin | last post by:
Can anyone help me get this update query right? The SELECT subquery does select the rows I want to update when taken on its own. However when I add the UPDATE piece it finds no rows to update....
4
by: Ed L. | last post by:
I think I'm seeing table-level lock contention in the following function when I have many different concurrent callers, each with mutually distinct values for $1. Is there a way to reimplement...
1
by: abhi81 | last post by:
Hello All, I have a table on which I have created a insert,Update and a Delete trigger. All these triggers write a entry to another audit table with the unique key for each table and the timestamp....
0
by: liviusbr | last post by:
Hello!I need to update the column SALARIU as follows : If the number of nume_sectie is 1 then it wil remain unchanged If the number of nume_sectie is 2 then it will be multiplied by 1.01 If the...
3
by: cris1978 | last post by:
Hi, I'm trying to do this query to update the results in a table, it's compiling and running without problems, but it's not updating the table, could you guys help me? Many Thanks! ...
2
osward
by: osward | last post by:
Hello there, I am using phpnuke 8.0 to build my website, knowing little on php programing. I am assembling a module for my member which is basically cut and paste existing code section of...
0
by: magnolia | last post by:
i created a trigger that will record the changes made to a table .everything works fine except the insert query.whenerever i try to insert a record it fires insert and update triger at the same time...
0
by: oskhan | last post by:
Hello Everyone, I have a little different problem and I though anyone might give me any idea that what is going wrong. I have a view which consists of 3 tables linked by UNION ALL, overall...
2
tjc0ol
by: tjc0ol | last post by:
Hi guys, Im just wondering that I cannot update my database throught datagrid datalist control, and the only thing works is that I can delete, cancel, edit but when I clicked update link...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.