I need to select status values form 1 of 4 possible columns, and I need to
pass the column name to select on as a parameter to the stored procedure.
Does anyone have an example of the syntax for the stored procedure?
such as:
CREATE PROCEDURE dbo.sp_Document_Select_ByStatus
(
@SelectColumn nVarChar
)
AS
SET NOCOUNT ON;
SELECT *
FROM Documents
WHERE (@SelectColumn = 0)
The columns to select on are BIT columns.
The error message on the above SP is:
'Syntax error converting the nvarchar value 'P' to a column of data type
int.'
At this point, the passed in parameter is a string "ProducerStatus"
HELP! I'm trying to pass parameters to a DTS Package(SELECT * FROM TABLE WHERE STATE = ?) What is the format from xp_cmdshell("exec master..xp_cmdshell 'dtsrun /Ssql /?????")? Any ideas? Thanks!
When I was but a young developer, I saw many databases that made use of XREF columns to manage the revision history of records; if a customer had a change of name, a new customer record was created with the new name and the old record was given a cross reference to the new record. Often the user was also required to enter a reason for the cross reference.
This was a very practical paradigm, easily understood by users as it mirrored business practices that were followed regarding paper records. It presented some issues for reporting however, as following xref chains did not translate easily into set based grammars.
Fast forward to the modern times. The prevalent approach has been the use of effective dating and transactional dating, which -- while possibly superior from an algebraic standpoint -- has its own drawbacks in application.
One weakness is the lack of a paradigm or strong metaphor. This often leads to imperfect implementations where data entry errors cannot be distinguished from more meaningful changes, or historical reporting that presents incorrect information because of the multiplicity of dates.
In addition, of particular interest is that often no facilities exist in modern systems to handle real world situations involving duplicate records: a customer is entered into a system, changes names, and is entered into the system again under the new name. The error is discovered some time later, after invoices or statements may have been sent to both customer records, but no function exists within the system to indicate that both records refer to the same entity. It becomes an issue for DBAs to deal with and resolve.
I would be interested to hear any comments or rebuttals from individuals as to which technique they feel is superior, and additional weaknesses or strengths of the two techniques.
I would like to know on how to pass a column name into a particular variable.
Example Table_name    Column_name Tablenm       Name Tablenm       Age Tablenm       Phone
The output will be:
ColName     Value Name       Alexander Grahambell Age         32 Phone       123456 Name       Sanosuke Sagara Age         35 Phone       246790
I'm writing a simple voting script and have columns for each options. I need to update the data based on whichever option the user picks.I.e...If the user picks option 1 then execute UPDATE mytable SET option1 = option1 + 1If the user picks option 2 then execute UPDATE mytable SET option2 = option2 + 1 Etc., etc.What's the best way to do that without building an ad-hoc SQL statement? There could be many options so I dont want to have lots of redundant SQL statements.Can I just use a varible in a stored proc and do something like this? UPDATE mytable SET @optionUserpicked=@optionUserpicked + 1Thanks in advance
HII m trying to use the following Store Procedure to search Suppliers... user provides a Column Name (Search By) and an Expression... but i m not getting it work properly... plz review it and tell me wots wrong with this stored procedure is... CREATE PROCEDURE dbo.SearchSupplier ( @Column nvarchar(50), @Expression nvarchar(50) ) AS SELECT SupplierID,Name,Address,Country,City,Phone,Fax FROM Supplier WHERE @Column LIKE '%'+@Expression +'%' OR @Column = @Expression RETURN Thanks
Is there a way to pass the column name as a query parameter?? If I use '@Question', like below, I get an error. If I change it to the actual name of the column 'Question1', it works fine. However, I need it to be dynamic so I can pass the column name [Question1, Question2, Question3, etc...] in and not have to define this for each question.
Doesn't Work!!
Code:
SELECT
1.0 * SUM(CASE WHEN @ColumnName > 1 THEN 1 ELSE 0 END) / COUNT(*) AS 'Good', 1.0 * SUM(CASE WHEN @ColumnName = 0 THEN 1 ELSE 0 END)/ COUNT(*) AS 'OK', 1.0 * SUM(CASE WHEN @ColumnName < 0 THEN 1 ELSE 0 END) / COUNT(*) AS 'Poor'
FROM tableA AS A INNER JOIN tableB AS B ON A.SessionID = B.SessionID
WHERE (A.SurveyID = @SurveyID) AND (A.SubmitDate BETWEEN @BeginDate AND @EndDate)
Works, but I need to pass in the column name dynamically.
Code:
SELECT
1.0 * SUM(CASE WHEN Question1 > 1 THEN 1 ELSE 0 END) / COUNT(*) AS 'Good', 1.0 * SUM(CASE WHEN Question1 = 0 THEN 1 ELSE 0 END)/ COUNT(*) AS 'OK', 1.0 * SUM(CASE WHEN Question1 < 0 THEN 1 ELSE 0 END) / COUNT(*) AS 'Poor'
FROM tableA AS A INNER JOIN tableB AS B ON A.SessionID = B.SessionID
WHERE (A.SurveyID = @SurveyID) AND (A.SubmitDate BETWEEN @BeginDate AND @EndDate)
I know passing table/column name as parameter to a stored procedure isnot good practice, but sometimes I need to do that occasionally. Iknow there's a way can do that but forget how. Can someone refresh mymemory?Thanks.Saiyou
We are working on C++ in eVC++ 3.0 environment (CE 3.0) with SQL CE 2.0.
We are trying with IRowsetIndex:: Seek method to access the data from the database. We are facing problem when we try to access data from the table having composite index other than the first column.
For example: The table ITEM contains the following columns: 1. ItemCode 2. PcNo 3. SubPcNo 4. BrandNo 5. DescText 6. ProductionKind 7. ProductionState 8. ClearingState 9. ST 10. TS
I€™ve two indexes for this table where the two indexes are 1. ItemKey1 on ITEM (ItemCode). 2. ItemKey2 on ITEM (PcNo, SubPcNo, BrandNo).
If I mention ItemKey1 as the index then the Seek method works perfectly.
But if I mention ItemKey2 as the index, then I€™m getting the error as €œDB_E_BADBINDINFO€?.
When we visted the MSDN for this problem we noted that: 1. When you use the Seek method on multiple fields, the Seek fields must be in the same order as the fields in the underlying table. If they are not, the Seek method fails. 2. When passing key values to an index rowset, the consumer performs these actions only for the number of key columns specified in the cKeyValues argument in IRowsetIndex:: Seek.
So we had the composite index such that columns of a composite index are physically aligned next to each other as in the table. When the first column of the index is the first column of the table as in index ItemKey1 we found that the seek method works perfectly. If we pass the index ItemKey2, we are again getting the error €œDB_E_BADBINDINFO€?.
What else have we missed out while passing the keys in IRowsetIndex:: Seek?
Hello, I'm quite new to T-SQL, but since I'm trying to create a statistics page on database contents (Counting savesets in Enterprise Vault saveset Databases) I prefer to do the coding in the databases. I create temp tables for the distinct partitions in the saveset table. Then I pass 2 variables to the EXEC function, but it seems unable to pass the ['+@idpartition+']-variable as a value: Declare @EVBase varchar(20)Declare @IdPartition INTSet @EVBase=(SELECT EVMbxName from Servers) Set @IdPartition=(SELECT TOP 1 Dist_Partitions FROM TEMP_EV1)EXEC('SELECT COUNT (IdPartition)FROM ['+@evbase+']..SAVESET SS LEFT OUTER JOIN SavesetStore SSS ON SS.SavesetIdentity = SSS.SavesetIdentityWHERE [IdPartition] = ['+@idpartition+'] AND StoreIdentifier IS NULL') Server: Msg 207, Level 16, State 3, Line 2Invalid column name '0'. If I change the last line to: WHERE [IdPartition] = 2 AND StoreIdentifier IS NULL')The script runs fine - but I need the value from the table. Any help will be appreciated. Best regards, Tim
i am using asp.net 2005 with sql server 2005. in my database table contains Table Name : Page_Content
Page_Id 101 102
1 Abc Pqr
2 Lmn oiuALTER PROCEDURE [dbo].[SELECT_CONTENT] (@lang_code varchar(max)) AS begin declare @a as varchar(max)set @a = @lang_code
Select page_id,@a From page_content end Here in this above store procedure i want to pass 101 to @lang_code here is my output, but this is wrong output
I have a simple Gridview control that has a delete command link on it.If I use the delete SQL code in line it works fine. If I use a stored procedure to perform the SQL work, I can't determine how to pass the identity value to the SP. Snippets are below...The grid<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2"> <Columns> <asp:BoundField DataField="member_id" HeaderText="member_id" InsertVisible="False" ReadOnly="True" SortExpression="member_id" /> <asp:BoundField DataField="member_username" HeaderText="member_username" SortExpression="member_username" /> <asp:BoundField DataField="member_firstname" HeaderText="member_firstname" SortExpression="member_firstname" /> <asp:BoundField DataField="member_lastname" HeaderText="member_lastname" SortExpression="member_lastname" /> <asp:BoundField DataField="member_state" HeaderText="State" SortExpression="member_state" /> <asp:CommandField ShowEditButton="True" /> <asp:CommandField ShowDeleteButton="True" /> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:rentalConnectionString1 %>" SelectCommand="renMemberSelect" SelectCommandType="StoredProcedure" DeleteCommand="renMemberDelete" DeleteCommandType="StoredProcedure" OldValuesParameterFormatString="original_{0}" > <DeleteParameters> <asp:Parameter Name="member_id" Type="Int32" /> </DeleteParameters> </asp:SqlDataSource>the SPCREATE PROCEDURE renMemberDelete@member_id as intAs UPDATE [renMembers] SET member_status=1 WHERE [member_id] = @member_idGO
Hi!I want to pass a column name, sometimes a table name, to a storedprocedure, but it didn't work. I tried to define the data type aschar, vachar, nchar, text, but the result were same. Any one know howto get it work?Thanks a lot!!Saiyou
I am trying to pass a variable set by a Row count transformation to a derived column transformation. There are actually three separate Row Count transformations storing to different variables. In the derived column trans. the expression i am using is @[User::ClientCount] and the variable type is Int32 and I am passing it to an I4 database column. After the derived column trans. all rows just come out with 0s in the row count columns. Does anyone know why this would be? Please let me know if you need more information.
After several hours of trying, I trow the towel in the ring and come here to ask a question.
Source system uses a timestamp column in the transaction tables. which is equal to a non-nullable binary(8) datatype (sql 2000 bol).
What I want to do is get the timestamp at the start of the transfer and at the end of the transfer of data. and store these in a controltable
I try to do this in 2 sql execute tasks:
sqltask 1: "select @@DBTS AS SourceTimestamp" and map the resultset to a variable. Here come's the first problem what variable type to take ?
DBNULL works (meaning it doesn't give errors) (BTW: is there a way to put a variable as a watch when debugging sql tasks ?)
INT64 and UINT64 don't work error message that types for column and parameter are different
STRING works
Then I want to store this variable back in a table of a different data source
sqltask2: "insert into controltable values(getdate(), ?)" and make an input parameter that takes the previous timestamp ...
if I took DBNULL as a type for the variable there doesn't seem to be a single parameter type that works ???
if i take STRING as a type for the variable I have to modify the sql to do the explicit conversion from string to binary so I change CAST(? as binary). It doesn't return any error but the value stored in the table is 0x00000000000 and not the actual timestamp.
Any help on this one ? Why are the INT64/Bigint not working here, you can perfectly do a convert(bigint, timestampfield) in sql ?
How came the SQL datatypes, and the variable datatypes, parameter datatypes are so badly alligned to each other (and all seem to use different names) ?
I am building a generic SSIS where it takes a text source file and converts to a destination source file . However in the process I want to set the row delimiter and the column delimiter dynamically through the package variable. So that I can use it for any file transfer.
I saw the option for row delimiter in the file connection string property but did not see any column delimiter option.
I have the following in my table. As you can see the Geo field is null (which is of type Geography), what I'm trying to do is populate that with an update statement by comparing the latitude and longitude for each row so I can then work out the distance, I've been following this tutorial to workout the distance which is giving me the desired results
[URL] ....
The issue I have is passing in the points i.e latitude and longitude and then updating the Geo field for the row, I currently have 11938 rows in my DB so I need to run this against all of them. I thought I had it I was thinking of update then select from the source but then I realized I need to pass the lat and long in for the points and that's where I got confused
I'm running 2014 enterprise and getting an error on this form of a query...it says the multi part identifier "mns.col3" could not be bound. I'm aware that a cross apply would be more appropriate but i'm just prototyping and probably going to move to a set based approach anyway.The udf returns a table.
select mns.col1, mns.col2 from table1 mns left join dbo.udf_udf1(@firstofmonth,@lastofmonth, mns.col3) x on 1=1
I have a excel file which has a column called "Code" and their values are A,B,C,D,E,F,G,H. I want to create a new column called "status" based on the values of "Code".
Code:
A B C D E F G H
If A,C,E,G then "status" = "Active" else if B,D,F,H then "Status" = "Inactive". I like to do it using "Derived Column".
The requirement is to have a table say 'child_table', with an Identity column to refer another column from a table say 'Parent_table'..
i cannot implement this constraint, it throws the error when i execute the below Alter query,
ALTER TABLE child_table ADD CONSTRAINT fk_1_ct FOREIGN KEY (child_id) REFERENCES parent_table (parent_id) ON DELETE CASCADE
the error thrown is : Failed to execute alter table query: 'ALTER TABLE child_table ADD CONSTRAINT fk_1_ct FOREIGN KEY (child_id) REFERENCES parent_table (parent_id) ON DELETE CASCADE '. Message: java.sql.SQLException: Cascading foreign key 'fk_1_ct' cannot be created where the referencing column 'child_table.child_id' is an identity column.
Hi guys, If I have a temporary table called #CTE With the columns [Account] [Name] [RowID Table Level] [RowID Data Level] and I need to change the column type for the columns: [RowID Table Level] [RowID Data Level] to integer, and set the column [RowID Table Level] as Identity (index) starting from 1, incrementing 1 each time. What will be the right syntax using SQL SERVER 2000?
I am trying to solve the question in the link below: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2093921&SiteID=1
Thanks in advance, Aldo.
I have tried the code below, but getting syntax error...
ALTER TABLE #CTE ALTER COLUMN [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT;
I have also tried:
ALTER TABLE #CTE MODIFY [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT;
Attached proc is working fine. But how should I pass the value of @LexNexID without manul key in the value. How can I call this proc. to update comment in table tblSEMS_FTP_FINAL automatically
Thk
CREATE PROCEDURE DBO.SP_SEMS_ADD_COMMENT ( @lexnexid int, @commentstring varchar(4000) ) AS
DECLARE @Comment varchar(4000) --DECLARE @CommentString varchar(4000) --DECLARE @LexNexID INT
--SET @LexNexID = 1 SET @CommentString = ''
DECLARE Test CURSOR FOR
SELECT convert(varchar(4000),Comment) COMMENT FROM dbo.TBLSEMS_FTP WHERE LEXNEXID = @LexNexID OPEN Test
Hi Guys, Im trying to pass a value from a C# page to the corresponding ASP page. I want to use this value in my SQL Query on the asp page within a Details View. Ive made the variable public in c# page. And im trying to concatenate it to my sql query within the <asp: SqlDataSource. Thanks.
A beginner's question I'm sure. When visitors have logged into my site, how do I then use their UserName as a parameter in an SQL WHERE clause so that I can pull up their detailed information. I'm using VB if additional code is required. Thanks in advance.
Hi, how to pass paremeters in sqldataadapter? here iam checking authentication using sqlcommand and datareader like that if iam checking authentication using dataset and sqldatareader how to use parameters?
SqlConnection cn = new SqlConnection("user id=sa;password=abc;database=xyz;data source=server"); cn.Open(); // string str = "select username from security where username='" + TextBox1.Text + "'and password='" + TextBox2.Text + "'"; string str = "select username from security where username=@username and password=@password"; SqlCommand cmd = new SqlCommand(str, cn); cmd.Parameters.AddWithValue("@username", TextBox1.Text); cmd.Parameters.AddWithValue("@password", TextBox2.Text); SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows) { Session["username"] = TextBox1.Text; FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
} else { Label1.Visible = true; Label1.Text = "Invalid Username/Password"; } ------------------------------------------------------------------------------------- like that if iam checking authentication using dataset and sqldatareader how to use parameters?SqlConnection cn = new SqlConnection("user id=sa;password=abc;database=xyz; data source=server"); cn.Open();ds = new DataSet(); string str = "select username from security where username=@username, password=@password";da = new SqlDataAdapter(str, cn); //how to pass parameters for that da.Fill(ds, "security"); Response.Redirect("dafault2.aspx");