Home » Asp.netRSS

temporary table stored procedure

hi,

how do i dyamically create a temporary table with a stored procedure?

i have a datasource on a page which returns all rows from 'type'. columns are url, b1,b2,b3

after this has been returned, i want a stored procedure to make a table with a row for each of the rows returned from sqldatasource1, where b1d,b2d,b3d = b1 -(subtraction) value of 'b1' querystring, b2 -(subtract) value of 'b2' querystring, b3 -(subtract) value of 'b3' querystring, all results to be shown as positive, even though results may sometimes be negative numbers.

then i want another column on this table to be called 'dif' and it is the total each row, (b1d,b2d and b3d)

then i want the row with the lowest 'dif' (random of the lowest if there are multiple with the same lowest dif) be selected (not from this table, but the row it was calculated from/refering from on the 'type' table).

is this possible? can someone help me with this? i have never creted a stored procedure before.. thanks so much if you can help


 

2 Answers Found

 

Answer 1

Please read the following article first
for temp table in sql

http://www.sqlteam.com/article/temporary-tables

 

Answer 2

hi,

try this

CREATE TABLE #sp_who3 

    SPID INT, 
    Status VARCHAR(32) NULL, 
    Login SYSNAME NULL, 
    HostName SYSNAME NULL, 
    BlkBy SYSNAME NULL, 
    DBName SYSNAME NULL, 
    Command VARCHAR(32) NULL, 
    CPUTime INT NULL, 
    DiskIO INT NULL, 
    LastBatch VARCHAR(14) NULL, 
    ProgramName VARCHAR(32) NULL, 
    SPID2 INT 

 
INSERT #sp_who3 EXEC sp_who2 'active' 
 
SELECT SPID, Status, HostName FROM #sp_who3 
    WHERE spid > 15 
 
DROP TABLE #sp_who3

for more information:

http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html

Thanks, 

 

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter