I'm trying to put together a script that would alter a table and add NOT FOR REPLICATION to the identity column on several hundred tables. Since I am unable to write a complex script to automate the entire process, I've decided to do the update one table at a time. Here is a script that I'm working on. I'm getting an error message when I try to run the script. Can someone please show me how to properly use variable with a wild card in a string ? or how to properly add this variables in this script?
DECLARE @Var1 AS CHAR(50), @tbn AS CHAR(50)
SELECT @tbn = 'tablename'
SELECT @Var1 = Name FROM SysIndexes WHERE Name LIKE 'pk%' AND Name LIKE '%' + @tbn + '%'
EXECUTE('ALTER TABLE [@tbn] DROP CONSTRAINT ' + @Var1
ALTER TABLE + @tbn + DROP COLUMN mkey
ALTER TABLE + @tbn + ADD viewkey INT IDENTITY (1,1) NOT FOR REPLICATION NOT NULL
ALTER TABLE + @tbn + ADD CONSTRAINT PK_+ @tbn PRIMARY KEY (mkey) WITH FILLFACTOR=90 ON [PRIMARY]
In the below section of code I'm connecing to a SQL database and when I use the "=" in the search it works ok, but when I try to add the ability to use wildcards by changin "=" to "LIKE" its not working
Working code:
Function GetName(ByVal first_Name As String) As System.Data.DataSet Dim connectionString As String = "server='(local)'; trusted_connection=true; database='FamilyInfo'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT Names.* FROM Names WHERE (Names.First_Name = @First_Name)" Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection
Dim dbParam_first_Name As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_first_Name.ParameterName = "@First_Name" dbParam_first_Name.Value = first_Name dbParam_first_Name.DbType = System.Data.DbType.StringFixedLength dbCommand.Parameters.Add(dbParam_first_Name)
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter dataAdapter.SelectCommand = dbCommand Dim dataSet As System.Data.DataSet = New System.Data.DataSet dataAdapter.Fill(dataSet)
Return dataSet End Function
Code that I would like to work
Function GetName(ByVal first_Name As String) As System.Data.DataSet Dim connectionString As String = "server='(local)'; trusted_connection=true; database='FamilyInfo'" Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT Names.* FROM Names WHERE (Names.First_Name LIKE '%' + @First_Name '+')" Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand dbCommand.CommandText = queryString dbCommand.Connection = dbConnection
Dim dbParam_first_Name As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter dbParam_first_Name.ParameterName = "@First_Name" dbParam_first_Name.Value = first_Name dbParam_first_Name.DbType = System.Data.DbType.StringFixedLength dbCommand.Parameters.Add(dbParam_first_Name)
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter dataAdapter.SelectCommand = dbCommand Dim dataSet As System.Data.DataSet = New System.Data.DataSet dataAdapter.Fill(dataSet)
I am developing one web site, in that I can upload files to sql server, it will save the uploaded file in binary type and we can download the files from there. Upto this everything is working perfectly. But now my problem is - i have to implement the wildcard character search in this site. The file name and extension will save on the database in different columns, and one more thing is file name is unique. I confused to implement wildcard search in this site, where i can implement this type of search in database or in my application with c#? So please help me to do this. I dont know that this is the right place to post this question or not. If it is not right place, please guide me to where I can post this. If it is right place, please help me to implement wild card search.
Hi All, I'm trying to use a very simple SQL String that check if a specific string exist in the DB. When I do the SQL and use a regular Connection I get the result. When I use a data set and on the table adapter I need to use the "LIKE %" method I get an error.
What should I write on the table adapter in order to make this search?
ItemID is a type string.
This is my SQL: SELECT itemID, itemName FROM Items WHERE (itemID LIKE @ItemIDTemp)
This sample give no result or
SELECT itemID, itemName FROM Items WHERE (itemID LIKE '%' + @ItemIDTemp + '%')
This sample return an error message "Data conversion failed. [OLEDB status value (if known)=2]"
I am using Conditinal split in my package. I need to remove certain rows which are matching my criteria. The criteria requires using wild card characters like, first_name = '%john%'.
Hi I am trying to include a string variable in a Select Statement. My problem is that when I code with the user name hard coated in the SQL Statement it works fine (see below:) cmd.CommandText = "SELECT UserPswd, StudioID, StudioCode FROM Users WHERE UserName = 'jdoe' " But when I try to use the String variable I get an error (See below): cmd.CommandText = "SELECT UserPswd, StudioID, StudioCode FROM Users WHERE UserName = " & StrUserName I know there must be something wrong with my syntax ?? Thanks Jackson
What I'm trying to accomplish is to execute a SQL string via exec and inside it set the value of a local variable. I understand that I cannot do this the way I'm currently doing it because an Executed string runs in a scope of its own so local variables are invisible. And sure enough this is the error I get. So how do I make this work?
Code snip:
declare @ErrMessage as varchar(1000) set @Sql = 'if exists ( select * from ' + @TargetTable + ' where (' + @ValueField + '=' + '''' + @NewValue + '''' set @Sql = @Sql + ' and ' + @TagField + '= ' + '''' + @Tag + '''' + '))' + @CRLF set @Sql = @Sql + 'set @ErrMessage = ''Insertion could not be performed. ' + @NewValue + ' is already an entry in the table. '''
So what I want is check if a certain table has entries...what table? I don't know, there are tens that this check will apply to. And if that tavle has an entry that satisfies the where clause then assign the appropriate error message to @ErrMessage.
I understand sp_executesql might do the trick because it allows passing local params back and forth.
Any ideas on how to make this work? I appreciate the effort.
I am trying to set the connection string in a connection manager at runtime. Here is what I have done:
1. Created a gv_DataSource, gv_Username and gv_Password
2. Created a ForEach Loop that reads DataSource, Username and password values from a variable (it is an For Each ADO loop Enumerator). The ADO recordset is read into by an Execute SQL task before the loop.
3. Mapped values from the recordset to variable in the ForEach loop's "Variable Mappings" page.
4. Used the variables in my Sybase OLEDB Connection Manager's "Expression" property, setting the "ConnectionString" property to:
5. I set the values in my database table for the connection-I set 2 connections for which I have Sybase OLEDB datasources setup.
When I run the package, I just get the first server's data twice, it doesn't set the second server's data during the second loop. I made sure the first one was working (i.e. the ConnectionString's property was being set by the data from the current variables) by setting the variables incorrectly in the variable properties page, and then running the package. So the first row of connection information is working, but the second loop around it doesn't seem to be working. I used a msgbox in a script task to show that the variables are mapping correctly in the loop, so it seems the second time around the connection information isn't taking from the variables.
We're converting to new student info system. Sometimes registrar entered the same school into the schools table but spelled it differently. Trying to find all student assigned transfer credits from the same school but the school name is different. My db shows a max of 9 different schools students have rec'd transfer credits. Spending too much time trying to figure out best way to do it w/o a ton of IF stmts. Looking at Soundex and Difference functions. Still looks like a lot of coding. how to compare up to 9 string variables in sqlserver 2008?
What i need is to create a function that compares 2 strings variables and if those 2 variables doesn't have at least 3 different characters then return failure , else return success.
I am new to SQL Server, DTS etc... But here is the question I have:
I have some files in a folder which have a the yr, month, date appended at the end, for e.g. testfile2005_11_28.log In a folder I have to look for the log files which are named testfileYYYY_MM_DD.log.
Dim item For Each item In logFolder.Files If (UCASE(item.Name) like ("TESTFILE" +"[0-9][0-9][0-9][0- 9]"+"_"+"[0-12][0-12]"+"_"+"[0-3][0-9]" + ".log") )Then msgbox item.Name End For
I am getting compilation error: "Sub or Function not found" in the If statement. Can anyone please help me?
I have a statement that works in compatibility mode 8 of SQL Server2000 while it fails in 7:declare @P3 intexec sp_prepexec @P3 output, N'@P1 float', N'select custname fromcustomer where custnr = @P1', 12600034custnr is a varchar(15). As long as the float p1 is less than1,000,000 the query returns correct results, but as soon as p1 isequal or greater than 1,000,000 the resultset is empty. I couldfigure, that above 1 million, sp_exec converts the float intoexponential format and compares this format to the string containingfixed format values. As said above, in mode 8 the statement returnscorrect results above 1,000,000.Please don't ask me, why we use float variables - I don't have anyinfluence on the statement - we isolated the statement with theprofiler.We are also currently dependent on the compatibility mode 7.I would be very grateful if you have any ideas, help or other issuesfor me.Thank you,Peter
Hi, I am using Visual Studio 2005. I am trying to create a ASP.net website and use a web form to get the results of an enquiry. It is almost the same as the presentation video on this website called "How to Create Data Driven Website", but I have added a new twist to it. I want to use the "LIKE" instead of "=" in my SQL statement and I want to use wild cards in the parameter value that I enter. <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <% dim str as string = "%" & textbox1.text & "%" </%> <asp:TextBox ID="TextBox2" runat="server" Visible="False" Text=str></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Submit" Width="87px" BackColor="Khaki" ForeColor="Navy" PostBackUrl="~/Default.aspx" /> and the ControlID of the Datagrid will take in the value of "TextBox2" instead of "TextBox1" as so: <SelectParameters> <asp:ControlParameter ControlID="TextBox2" DefaultValue="SO06000001" Name="SO" PropertyName="Text" Type="String" /> However the syntax above does not work. May I ask what is the correct syntax? Thanks. Peter
I am very new to sql and would like some help with a simple select statement. I am trying to pull birthdates using the following code. I can get the query to run but some of the dates are not between the parameters. What am i doing wrong?
SELECT Employees.EmployeeStatusID, People.FirstName, People.LastName, People.BirthDate FROM Employees FULL OUTER JOIN People ON Employees.SystemAssignedPersonID = People.SystemAssignedPersonID WHERE (People.BirthDate BETWEEN '10 - 01 - 1900' AND '12 - 15 - 2007') ORDER BY People.BirthDate
Hello everyone, trying to use stored procedure for my datagrid. in there i have the parameter that i would like to combine with wild character to retrieve some data..Does not work. Please help to come up with right syntax... here is the code: SELECT First_Name, Last_Name, Address, City, Customer_ID, Company_Name, State, ZIP, Phone_Number_1, Phone_Number_2, Email FROM v2_Customers WHERE (City = @search_text) OR (First_Name = @search_text) OR (Last_Name LIKE '%'+@search_text) OR (Address = @search_text)
I want to retrieve data from SQL containing non English character but fail, can anyone shed me some light?
What I use currently:
Dim strSQL As String strSQL = "SELECT ArticleID, " strSQL &= "ISNULL(Body, '') AS Body, " strSQL &= "ISNULL(Subject, '') AS Subject " strSQL &= "FROM Articles " strSQL &= "WHERE (Subject LIKE N'%' + @Keyword + '%' OR [Body] LIKE N'%' + @Keyword + '%') " Dim con As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString")) Dim cmd As New SqlDataAdapter(strSQL, con) cmd.SelectCommand.Parameters.Add("@Keyword", SqlDbType.NVarChar).Value = keyword ...
I'm not so sure where should I place the letter "N", I use :
SELECT ArticleID, ISNULL(Body, '') AS Body, ISNULL(Subject, '') AS Subject, FROM Articles WHERE (Subject LIKE N'%SomeNonEnglishString%' OR [Body] LIKE N'%SomeNonEnglishString%')
in Query Analzyer, it works! But it failed in my program... oh my god...
How do I use table names stored in variables in stored procedures?
Code Snippetif (select count(*) from @tablename) = 0 or (select count(*) from @tablename) = 1000000
I receive the error 'must declare table variable '@tablename''
I've looked into table variables and they are not what I would require to accomplish what is needed. After browsing through the forums I believe I need to use dynamic sql particuarly involving sp_executesql. However, I am pretty new at sql and do not really understand how to use this and receive an output parameter from it(msdn kind of confuses me too). I am tryin got receive an integer count of the records from a certain table which can change to anything depending on what the user requires.
Code Snippet
if exists(Select * from sysobjects where name = @temptablename) drop table @temptablename
It does not like the 'drop table @temptablename' part here. This probably wouldn't be an issue if I could get temporary tables to work, however when I use temporary tables i get invalid object '#temptable'.
Heres what the stored procedure does. I duplicate a table that is going to be modified by using 'select into temptable' I add the records required using 'Insert into temptable(Columns) Select(Columns)f rom TableA' then I truncate the original table that is being modified and insert the temporary table into the original.
Heres the actual SQL query that produces the temporary table error.
Code Snippet Select * into #temptableabcd from TableA
Insert into #temptableabcd(ColumnA, ColumnB,Field_01, Field_02) SELECT ColumnA, ColumnB, Sum(ABC_01) as 'Field_01', Sum(ABC_02) as 'Field_02', FROM TableB where ColumnB = 003860 Group By ColumnA, ColumnB
TRUNCATE TABLE TableA
Insert into TableA(ColumnA, ColumnB,Field_01, Field_02) Select ColumnA, ColumnB, Sum(Field_01) as 'Field_01', Sum('Field_02) as 'Field_02', From #temptableabcd Group by ColumnA, ColumnB
The above coding produces
Msg 208, Level 16, State 0, Line 1
Invalid object name '#temptableabcd'.
Why does this seem to work when I use an actual table? With an actual table the SQL runs smoothly, however that creates the table names as a variable problem from above. Is there certain limitation with temporary tables in stored procedures? How would I get the temporary table to work in this case if possible?
Is there any tool available that can encrypt Credit card numbers or other fields stored in the database? For example, when a customer enters his credit card number or his password on the site, is there a way by which the Front end can encrpt the field before storing it in the database and decrypt it when it the customer requests it, through the application?
table Orders ord_id int ord_CudtomerID int, ord_CardNo char(16)
Example values in table CreditCardRange 1 , 5000 0000 2000 1234 , 5000 0030 3000 1356
Example values in table Orders 1, 1, 5000 0010 2000 2333
Does sql provide any magic finction to help in following select
select T1.* from Orders T1 join CreditCardRange T2 on T2.ccr_CudtomerID = t1.ord_CudtomerID and SQLMagicFunction(T1.ord_CardNo) between SQLMagicFunction(T2.ccr_CardRangeFrom ) and SQLMagicFunction(T2.ccr_CardRangeTo )
My team is currently building a system for the Windows CE 5.0 platform that uses a SQL CE database to synchronize with a SQL Server 2005 database. During this synchronization process, the application needs to pull down a good bit of data and it reaches its cap for memory. A possible solution for this is to use an SD card for storing the database. However, when the Synchronization process is run, the following SQL Exception Occurs:
HResult = -2147467259 Message = "SQL Mobile encountered problems when creating the database." NativeError = 28558 Source = "Microsoft SQL Server 2005 Mobile Edition" StackTrace = at System.Data.SqlServerCe.NativeMethods.CheckHRESULT() at System.Data.SqlServerCe.SqlCeReplication.AddSubscription() Our Trace at System.Windows.Forms.Control.OnClick() at System.Windows.Forms.Control.WnProc() at System.Windows.Forms.Control._InternalWnProc() at Microsoft.AGL.Forms.EVL.EnterMainLoop() at System.Windows.Forms.Application.Run() Main
The connection string we're using for the Mobile Database is "data source=Storage CardDatabase.sdf"
Has anyone ever had any problems when trying to perform Merge/Replication on expandable Flash Memory and if so, how did you solve them?
SQL mobile apps like - .Net Frame work, SQLCE mobile etc - can they be install on the Storage Card? I am running out of space on my Verizon 6700 and don't have enought memory to install on the device. I cleaned up as much as I could still not enough space on the device.
I am new to SQL developement ( am .Net developer). I need to implement a stored proc in sql 2005 on CC expiration task.
I have CC exiration date. By using expiration date (like '01/08'),
Conditions are:
1. If CC expiring within 31 days. Stored proc will write the Customer data in EmailNotification table with message type =1. (Customer will not get second notification until 14 days before expiring)
2. If CC expiring within 14 days. Stored proc will write the customer data in EmailNotification table with message type =2. (Customer will not get second notification until 11 days before expiring)
3. If CC expiring within 11 days. Stored proc will write the customer data in EmailNotification table with message type =3. (Customer will not get second notification until 2 days before expiring)
4. If CC expiring within 2 days. Stored proc will write the customer data in EmailNotification table with message type and update orderStatusID to On Hold CC Expired in order table.
My Tables are
1.
TABLE [dbo].[Order]( [OrderID] [int] IDENTITY(1,1) NOT NULL, [CustomerID] [int] NOT NULL, [CustomerCode] [nvarchar](12) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [DateCreated] [datetime] NOT NULL, [DateOrdered] [datetime] NOT NULL, [OrderTypeID] [int] NULL, [OrderStatusID] [int] NULL, [LastProcessDate] [datetime] NULL,
2. CREATE TABLE [dbo].[Payment]( [PaymentID] [int] IDENTITY(1,1) NOT NULL, [OrderID] [int] NOT NULL, [OrderPaymentType] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [PaymentType] [nvarchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CreditCardNumber] [varbinary](max) NULL, [Last4DigitsOfCreditCardNumber] [nvarchar](4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [ExpirationDate] [varbinary](max) NULL, [CVV2] [varbinary](max) NULL, [Amount] [numeric](18, 2) NOT NULL
3. CREATE TABLE [dbo].[Customer]( [CustomerID] [int] IDENTITY(1,1) NOT NULL, [CustomerCode] AS ([dbo].[udf_FormatCode]('RS',[CustomerID])), [Email] [nvarchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [FirstName] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [MiddleName] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [LastName] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [DateCreated] [datetime] NOT NULL, [DateModified] [datetime] NOT NULL, [MembershipTypeID] [int] NULL
Please atleast basic structure of stored proc code. It will greatful to me.
I develop a app on PPC 4.20 using SQLServer 3.1. I developed a o/r mapper whitch auto-creates the Database and Tables using attribute-decorated objects. That all works fine - as long as my Database is in \MyDocuments . Trying to store the Database in \Storage Card\test.sdf, whitch is absolut neccessary because it will become to big for storing onto device, I get error 25113, "A not supportes operation to host was called" (Translated from German)
When I trie to copy a Database to the SD-Card, inserts are not commited.
Is it not supported to store Databasefiles on a Flashcard?
My development-environment is .net 2.0 sp2, device-emulator v2, Windows XP, vs2005. In the emulator, i have linked a windows-based directory as storagecard.
What am I doing wrong??
class SQLManager { private static SQLManager instance = null;
Hi friends, i got an issue on my website regarding theft of cc details...sql db contains credit card details table ... it has been hacked by someone...we have analysed that latest cards are misused.. i have tried different scenarios(sql injection) ... what are all the key things have to check and implement .can any one advise please..
Using shared folder in windows mobile 5 emulator, it is not possible to create a database (sqlserver mobile 2005) in the emulated storage card.
The error "sql mobile made an unsupported request to the host operating system. Minor Err 25133 is raised. Reading or writing file from/to the emulated storage card occurs without error.