SQL Server :: IDENT_CURRENT To Parameter?
Oct 19, 2010
I have to insert data in Table1 (which i can). After that I must insert data into Table2 using ID of last entry in Table1 as a parameter in my stored procedure. Don't know how to set the value of parameter to that Table1.ID and use it after.I have some code but don't want to mess up here. What is the best way to do this and should it be done all in one stored procedure or not?
View 2 Replies
Similar Messages:
Jan 19, 2010
I'm trying to insert data into two tables that are related within a store procedure. After the first insert I want to get the id of the inserted row to use as a parameter during the insertion of data in the other table. I'm sure this is a common task, and I have looked into things like scope_identity(), @@identity and ident_current. However I'm not sure exactly how to use the id as a parameter.My attempt now looks like:
DECLARE @RETURN_VALUE
INSERT INTO Table1(test_name) VALUES ('asdf')
@RETURN_VALUE = SCOPE_IDENTITY()
INSERT INTO Table2(test_name) VALUES(@RETURN_VALUE)
View 4 Replies
Aug 9, 2010
Here is my stored proc
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
Create PROCEDURE [dbo].[sp_GetNextSeq] (
@p_NextSeqNo int = NULL OUTPUT
)
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
BEGIN TRANSACTION
Generate Next Sequence Number
[code]...
View 7 Replies
Oct 29, 2010
I have got a problem about setting the optional parameter to NULL in sql sp. Initially I set all the parameters null in the sql sp. That's OK. But I would like to set the parameters to Null again if a particular parameter has a value of - 1 by using the "IF ELSE" statement block. However, the problem was that I was unable to set the parameter to NULL in the IF ELSE statement. So please correct my IF ELSE statement in the store procedure. This is really urgent and important for my project.
spGetMealsByNutritions]
@MealTypeID Int,
@Gluten Bit = Null,
@Dairy Bit = Null,
@Egg Bit = Null,
@Fish Bit = Null,
@Veg Bit = Null,
@Pork Bit = Null,
@Beef Bit = Null,
@Soy Bit = Null,
@Sesame Bit = Null
[code]...
View 7 Replies
Aug 13, 2010
i have a SP
[Code]....
as you can see from the SP, i need save in some variable because i have to create a dynamic SQL query who select with an "or" or "AND" from web form parametersthe problem is concatenate the SP parameter to my query
actually, this SP returns the string : "select * from...." and not the resultset!
View 5 Replies
Feb 24, 2011
I am trying to return a sum total figure from a stored procedure by using the output parameter. When I execute the stored procedure in SQL it returns 0 or a valid number like it should but when I try to use the webmethod listed below I keep getting a 0 even when I should get a valid number back.
ALTER PROCEDURE spGetCustSum
@CustomerCode CHAR(4),
@Sum AS INTEGER OUTPUT
AS
BEGIN......
Am I missing a step or have some wrong code in this method?
View 4 Replies
Sep 7, 2010
im passing one input parameter to the SP, based on that parameter i have written the code like below create procedure SP1(@inpName varchar(10))
declare @where varchar(20);
if @inpName = 'ABCD'
@where = 'A';
else if @inpName = '1234'
@where = '1';
else if @inpName = 'AB12'
@where = 'A,B';
SELECT * FROM TABLE1 WHERE COLUMN1 IN(@where);
Now the above query was fine if its 'ABCD' or '1234', but if its 'AB12' then query failed.
How to resolve this issue.?
View 2 Replies
Oct 12, 2010
i have update sp for users table ,,, i want to store in "Transactions Table" which exactly the fields updated and what is the old value and new value ,, just the updated !!look at this sp code : [Code]....
my question is :'@@column-name' i want to return the parameter for example ---> @user_name ,,, but how ?
View 3 Replies
Oct 7, 2010
how do I add an output parameter to a Stored Procedure that returns a code or string to the calling app
View 1 Replies
Jul 25, 2010
I have GridView1 and SqlDataSource1. I use EnableEditing to GridView1. This is Code of GridView
<
asp:GridView
ID="GridView1"
Width="100%"
runat="server"
AutoGenerateColumns="False"
BackColor="White"
BorderColor="#3366CC"
BorderStyle="None"
BorderWidth="1px"
CellPadding="4"
DataKeyNames="DoctorID"
DataSourceID="SqlDataSource1">
<RowStyle
BackColor="White"
ForeColor="#003399"
/>
<Columns>
<asp:BoundField
DataField="DoctorID"
HeaderText="DoctorID"
InsertVisible="False"
ReadOnly="True"
SortExpression="DoctorID"
/>
<asp:BoundField
DataField="DoctorName"
HeaderText="DoctorName"
SortExpression="DoctorName"
/>
<asp:BoundField
DataField="City"
HeaderText="City"
SortExpression="City"
/>
<asp:BoundField
DataField="Str"
HeaderText="Str"
SortExpression="Str"
/>
<asp:BoundField
DataField="StrRegion"
HeaderText="StrRegion"
SortExpression="StrRegion"
/>
<asp:BoundField
DataField="StringLevels"
HeaderText="StringLevels"
SortExpression="StringLevels"
/>
<asp:BoundField
DataField="Streat"
HeaderText="Streat"
SortExpression="Streat"
/>
<asp:BoundField
DataField="Email"
HeaderText="Email"
SortExpression="Email"
/>
<asp:BoundField
DataField="Mobile"
HeaderText="Mobile"
SortExpression="Mobile"
/>
<asp:BoundField
DataField="HomePhone"
HeaderText="HomePhone"
SortExpression="HomePhone"
/>
<asp:BoundField
DataField="ClinicPhone"
HeaderText="ClinicPhone"
SortExpression="ClinicPhone"
/>
<asp:BoundField
DataField="Fax"
HeaderText="Fax"
SortExpression="Fax"
/>
<asp:BoundField
DataField="address_details"
HeaderText="address_details"
SortExpression="address_details"
/>
<asp:BoundField
DataField="Expr1"
HeaderText="Expr1"
SortExpression="Expr1"
/>
<asp:BoundField
DataField="VisitPlaceStr"
HeaderText="VisitPlaceStr"
SortExpression="VisitPlaceStr"
/>
<asp:CommandField
ShowEditButton="True"
/>
</Columns>
<FooterStyle
BackColor="#99CCCC"
ForeColor="#003399"
/>............
View 1 Replies
Aug 7, 2010
i am developing a crystal report in my asp.net site with MS SQL7.0 backend the problem is that when i m using it in lan from my pc it is working but when i deploy it on server having statc ip creystal report is not opening following error occured.
Logon failed. Details: ADO Error Code: 0x Source: Microsoft OLE DB Provider for SQL Server Description: Invalid authorization specification SQL State: 28000 Error in File C:WINDOWSTEMP ptQuotation {25579341-6096-4C84-91C5-6571EBC8991F}.rpt: Unable to connect: incorrect log on parameters.
View 2 Replies
Jan 26, 2011
I have an application with 40 or so separate databases that share a number of identical table schemas. Each is for a separate agency that performs functions identical (nearly) to the others. I have a number of reports that involve complex queries that each agency is required to produce. There is a "top-level" agency that would like to run the same reports but have the data consolidated for ALL agencies. I have tried having the query generated simply re-produced for each sub-agency by using a "UNION" ..
SELECT .... FROM [Agency].[dbo].[Table] ... UNION SELECT ... FROM [Next Agency].[dbo].[Table]....
This works for a few agencies selected/included but when they try to select all agencies or more than a few, it fails because the query is too large. I have tested a stored procedure:
CREATE PROC Test @DB AS
SELECT ... FROM [@DB].[dbo].[Table]...
Thinking I can build a smaller query by having up to 40 items of "EXEC Test (db) UNION EXEC Test (next db)" That also fails.... won't permit the database specifier as a parameter (plus, I don't know if I can do a UNION on the EXEC results).
View 9 Replies
Feb 14, 2011
I tried to develop a dynamic pivot query with following code to avoid hard coding. I can got the 'Q1, Q2, Q3, Q4' dynamically and assigned to @(@quarter. But it cannot be passed to the pivot query.
[Code]....
View 7 Replies
Oct 16, 2010
I'm trying to pass values in a SessionState from one page to another and then post them to a SQL database. When I click on the submit button on my submit page, I get this error:
Failed to convert parameter value from a String to a DateTime.
Here is my submit page:
[Code]....
I've verified that all of the input matches what I'm looking for on the SQL side.
View 31 Replies
Dec 31, 2010
i am passing the serverside control as parameter, but it throws OBJECT ERROR.
View 5 Replies
Jan 14, 2011
I have a server control that performs some logic. I'd love to provide a default implementation of this logic in the code of the control, but allow a developer to pass an alternate implementation of this logic in as a delegate, if they wish.
So...
<prefix:MyControl FooLogicMethod="MyUtilityClass.MyFooLogicMethod" runat="server"/>
If they don't specify this, I'll use my default method. If they do specify it, I'll use the method they passed in.
Can I do this as a delegate, or do I need to reflect it?
View 1 Replies
Aug 6, 2010
[URL]as the iage upstairs i have to create a filter in my sql stored procedure
so, my difficulties is switch the "and" and "OR" paramers located in the webFormhow can i do that?i was thinking to save in a temporaney variable : @temp='and field=1'
but my difficulties is to concatenate with a principal query and execute it
View 2 Replies
Jan 9, 2011
i made stored procedure like that
select AssetCode ,Description
,EquipmentID from [FATMS].[fnMaintenanceHeaderRead](@ContextUser,@ContextClient,@ContextLang,@ContextApp,@ContextOrg,'1',@fnXmlParamMaintenanceHeader)
MH
where MH.Status
IN
( @Status)
when i put three values for parameter (@status) not work but one value work
how to put three values please to parameter @status when excecute that stored procedure
EXEC @return_value = [FATMS].[spMaintenanceReport]
@ContextUser = N'4806',
@ContextClient = 1,
@ContextLang = N'en-US',
@ContextApp = N'FATMS',
@ContextOrg = 23,
@ActionCode = N'1',
@MaintenanceHeaderId='',
@SearchText='',
@EntryType='0',
@Status=N' '
SELECT 'Return Value' = @return_value
View 12 Replies
Nov 21, 2010
I have a stored procedure that is close to working. It takes the values of a details view puts them into the respective table 'entity' then should also put the @@identity into 'entloan' and should put the LoanID which is in the query string of the page the detials view is loaded on, into the LoanID field of entLoan as well. Everything works except for getting the querystring value to pass to a insert variable on my stored procedure.
Stored Procedure
[Code]....
I do not have a LoanID Insert parameter set as it is not in entity table:
[Code]....
I have been playing around with different code in the backend but always get errors:
[Code]....
View 2 Replies
Jan 11, 2011
When i try to pass this string "- !@#$%^&*()_+|}{:"?><<>?/.,';[]`" as a parameter to SQL Server Reporting it crashes. Here is code sample
ReportParameter[] ReportParams = new ReportParameter[1] { new ReportParameter("Name", HERE-COMES-SPECIALSTRING)
IS there any way to pass special character safely like in SP's we use @ sign for parameter name
View 2 Replies
Sep 17, 2010
I have a GridView sourced by a SQL Server stored procedure with several databound fields, including a money column for item values. My stored proc returns the data through a SELECT and everything looks good. The stored proc also has a single output parameter that sums the total value of the displayed data, and this value is displayed in a label above the GridView.
View 7 Replies
Jan 26, 2010
This may be elementary user control stuff, but I can't get it to work.
How can I pass the Membership.GetUser.UserName variable (or any variable) through a user control parameter at load time?
[Code]....
The only thing that I was able to do was to create the User Control object in the code behind and then add it to the page. Although that works, it doesn't seem like the correct way to program.
View 1 Replies
Mar 9, 2011
[Code]....
why I am not getting the desired result. I want to retrieve records in DataReader and still I am not getting any result.
View 4 Replies
Oct 6, 2010
I have a gridview which I databind to EntityModel
This typically looks like
something a
something b
companyID
on Login I get and set the compnay which has the ID so what in essence I want to do is on databind set the Where clause of data source to what the server side paramter for company ID is.
View 1 Replies
Jul 28, 2010
I want to know, how do i send a multivalue parameter from C# to Stored Procedure which is used in WHERE CLAUSE in IN statement?
for eg:
CREATE PROCEDURE [dbo].[sp_GetPolicyDivOff1]
@Insid varchar(5000)=null
AS
SET NOCOUNT ON
SELECT MST_GroupCompany.GC_Name,MST_DivisionalOffice.DIV_Name FROM MST_DivisionalOffice INNER JOIN MST_GroupCompany ON
MST_DivisionalOffice.DIV_FK_GC_ID=MST_GroupCompany.GC_ID where GC_Name IN(@Insid)
View 10 Replies