July 28, 2011 at 7:41 am
Hi,
I have this store procedure..the problem is that the result is for all fields NULL
What is wrong?
alter PROCEDURE [dbo].[LITABVERIFICAGIACENZA_INSERT] (@Codarticolo VarChar(50),@codlotto VarChar(50)OUTPUT,@giacenza decimal(38,6) OUTPUT, @datamodificalotto datetime output) AS
CREATE TABLE #listalotti (
[CODARTICOLO] [VARCHAR] (50) ,
[CODLOTTO] [VARCHAR] (15) ,
[GIACENZA] [DECIMAL](38,6) ,
[DATAMODIFICALOTTO] [datetime] ,
)
BEGIN
INSERT INTO #listalotti ( Codarticolo, codlotto, giacenza, datamodificalotto)
SELECT @Codarticolo, @codlotto, @giacenza, @datamodificalotto
FROM ANAGRAFICALOTTI INNER JOIN VISTAGIACENZEPARTITE ON VISTAGIACENZEPARTITE.CODARTICOLO = ANAGRAFICALOTTI.CODARTICOLO
WHERE ANAGRAFICALOTTI.CODARTICOLO=@Codarticolo
GROUP BY ANAGRAFICALOTTI.DATAMODIFICA
ORDER BY ANAGRAFICALOTTI.DATAMODIFICA
END;
July 28, 2011 at 7:44 am
{edit} sorry, wrong post.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 28, 2011 at 7:51 am
You have 4 parameters inbound (3 of them are output). The body of your procedure doesn't actually do anything. You create a temp table and populate it with the values you passed in. Why bother with a temp table that is nothing more than the values you passed in? Even if this is used in another process it does not provide any benefit because the calling application/procedure already has all the information that was passed in.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 8:18 am
what you suggest? To create a "real" tale?
How can I check if my value are really written in my table?
I need to check the generated recordset
Thanx
July 28, 2011 at 8:27 am
ferrarielly (7/28/2011)
Hi,I have this store procedure..the problem is that the result is for all fields NULL
What is wrong?
alter PROCEDURE [dbo].[LITABVERIFICAGIACENZA_INSERT] (@Codarticolo VarChar(50),@codlotto VarChar(50)OUTPUT,@giacenza decimal(38,6) OUTPUT, @datamodificalotto datetime output) AS
CREATE TABLE #listalotti (
[CODARTICOLO] [VARCHAR] (50) ,
[CODLOTTO] [VARCHAR] (15) ,
[GIACENZA] [DECIMAL](38,6) ,
[DATAMODIFICALOTTO] [datetime] ,
)
BEGIN
INSERT INTO #listalotti ( Codarticolo, codlotto, giacenza, datamodificalotto)
SELECT @Codarticolo, @codlotto, @giacenza, @datamodificalotto
FROM ANAGRAFICALOTTI INNER JOIN VISTAGIACENZEPARTITE ON VISTAGIACENZEPARTITE.CODARTICOLO = ANAGRAFICALOTTI.CODARTICOLO
WHERE ANAGRAFICALOTTI.CODARTICOLO=@Codarticolo
GROUP BY ANAGRAFICALOTTI.DATAMODIFICA
ORDER BY ANAGRAFICALOTTI.DATAMODIFICA
END;
I think what's being described is this:
You aren't selecting from the temp table, you are inserting into it and then doing nothing. Your query:
INSERT INTO #listalotti ( Codarticolo, codlotto, giacenza, datamodificalotto)
SELECT @Codarticolo, @codlotto, @giacenza, @datamodificalotto
FROM ANAGRAFICALOTTI INNER JOIN VISTAGIACENZEPARTITE ON VISTAGIACENZEPARTITE.CODARTICOLO = ANAGRAFICALOTTI.CODARTICOLO
WHERE ANAGRAFICALOTTI.CODARTICOLO=@Codarticolo
GROUP BY ANAGRAFICALOTTI.DATAMODIFICA
ORDER BY ANAGRAFICALOTTI.DATAMODIFICA
will not insert anything if the join/group criteria returns no rows. There is no way for us to know what you are trying to do with this. You take 4 input/output parameters and then insert into a temp table based on a join that is not defined by table schemas/sample data. You could insert 1 record or 1 million records and there is no way to know which. For what you are trying to describe might be this:
INSERT INTO #listalotti ( Codarticolo, codlotto, giacenza, datamodificalotto)
SELECT @Codarticolo, @codlotto, @giacenza, @datamodificalotto
SELECT * FROM #listalotti
Are you trying to return values in the OUTPUT Parameters? If so you need to do a select to get those values, maybe something like this:
SELECT
@Codarticolo = [SomeField1],
@codlotto = [SomeField2],
@giacenza = [SomeField3],
@datamodificalotto = [SomeField4]
FROM
dbo.[SomeTable]
WHERE
[SomeCriteria] = {some value}
July 28, 2011 at 8:41 am
be careful with this. For this to provide any useful information you need to make sure this select will return ONLY 1 row.
SELECT
@Codarticolo = [SomeField1],
@codlotto = [SomeField2],
@giacenza = [SomeField3],
@datamodificalotto = [SomeField4]
FROM
dbo.[SomeTable]
WHERE
[SomeCriteria] = {some value}
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 8:42 am
ferrarielly (7/28/2011)
what you suggest? To create a "real" tale?How can I check if my value are really written in my table?
I need to check the generated recordset
Thanx
Maybe if you explain what you are trying to do we can help. Keep in mind that with the way this is coded your "recordset" is going to contain only the values you passed in. You will have a whole collection of identical records for each row in the query.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 8:56 am
what I need to do is:
receiving a codart from an external code..I need to do a select in 2 different table extracting the rows related to this specific codart..
The result may be 1 or N rows...
Then I need to write this rows in a table (temp or real table..)
I need to do that..
Have you an example to do so?
July 28, 2011 at 9:00 am
ferrarielly (7/28/2011)
what I need to do is:receiving a codart from an external code..I need to do a select in 2 different table extracting the rows related to this specific codart..
The result may be 1 or N rows...
Then I need to write this rows in a table (temp or real table..)
I need to do that..
Have you an example to do so?
Even if you have an exaple that exctract value from a sinlgle table...IS FINE!!!!!!!!!!!!!
July 28, 2011 at 9:02 am
You want to receive a parameter and retrieve data from a current table based on what they passed in?
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 9:05 am
yes correct...
I need to pass the codart value and retrive all rows related to this article saving them on a table
July 28, 2011 at 9:09 am
Here is a generic template.
create procedure blah
(
@parameter1 int,
@parameter2 int
) as
begin
select MyCols from Table1
join Table2 on Table1.ID = Table2.ID
where MyVal1 = @parameter1 and MyVal2 = @parameter2
end
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
July 28, 2011 at 9:10 am
If you need to save this to a table just change the select to an insert.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply