Help, I am trying to update 1000 rows. They have the wrong extension of an image file and I'd like to change the extension only. I have tried using the following code
declare @ptrval binary(16) select @ptrval = textptr(images) from copyimages where images like '%.jpgg%' updatetext copyimages.images @ptrval 8 5 with log '.jpg' go
This works but it only updated one record. I would like it to update all the records. I have tried using a counter with nocount on but I am getting an error. Can anyone please tell me how to go about that??
Also how would I go about it if the image names were not the same length?
I would appreciate any help I can get. Thank you JG
I need to update/change the text in a table column of data type TEXT.It's a smaller set of records (72) where I need to append onto the enda string of text, the same for all records.I don't quite understand how UPDATETEXT and WRITETEXT work, but hereis how I would write the Update query were the field not a TEXT type.Update Matters Set Description = Description + ' (Stylized)'
I have a question on the UPDATETEXT function (SQL 2000)The below query works and only updates the record where p.pub_id =pr.pub_id.I just don't quite understand why only 1 record is updated when theUPDATETEXT statementdoes not specify anything except pointer value. Is it no possible for 2rows in a table with a text column to have the same pointer value?Does this query scan all pr_info in the pub_info table?USE pubsGOEXEC sp_dboption 'pubs', 'select into/bulkcopy', 'true'GODECLARE @ptrval binary(16)SELECT @ptrval = TEXTPTR(pr_info)FROM pub_info pr, publishers pWHERE p.pub_id = pr.pub_idAND p.pub_name = 'New Moon Books'UPDATETEXT pub_info.pr_info @ptrval 88 1 'b'GOEXEC sp_dboption 'pubs', 'select into/bulkcopy', 'false'GOAlso, what is the importance of 'select into/bulkcopy', 'true' ?Thanks
I'm trying to run the following SQL against my column, Testtbl.Task
I want to replace where the ampersand sign got HTML encoded to "&", and I want to strip it down to only the ampersand sign and delete the "amp" and the ";", that's why my parameters for the UpdateText are 0 and 8 with no update text value.
It executes, but I still have the HTML encoding for the ampersand sign.
USE WI GO EXEC sp_dboption 'WI', 'select into/bulkcopy', 'true' GO DECLARE @ptrval binary(16) SELECT @ptrval = TEXTPTR(Task) FROM Testtbl WHERE Task like '%amp;%' UPDATETEXT Testtbl.Task @ptrval 0 8 GO EXEC sp_dboption 'WI', 'select into/bulkcopy', 'false' GO
I'm trying to run the following SQL against my ntext column, Testtbl.Task I want to replace where the ampersand sign got HTML encoded to "&", and I want to strip it down to only the ampersand sign and deletethe "amp" and the ";".It executes, but I still have the HTML encoding for the ampersand sign if the issue is NOT the first character in the ntext column. If it's the first part of the ntext column, then it works.
Hi all, I am creating a search table where the keywords field is madeup of several text fields and this is causing me some problems. I canconcatentate the text ok but i can't seem to concatenate matchingrecords here is the cursor loop. I'm not a fan of cursors but alsodidn't see another way of achieving this.declare @ptr1 varbinary(16)declare @Ptr2 varbinary(16)declare @profileid intdeclare @x intset @profileid = 0while @profileid is not nullbeginselect@profileid = min([id]),@ptr1 = MIN(textptr(text1))from #holdingwhere [id] @profileiddeclare c2 cursor fast_forward forselect textptr(searchterms), datalength(searchterms)from searchwhere search.[id] = @profileidopen c2fetch c2 into @ptr2, @xwhile @@fetch_status = 0beginupdatetext search.searchterms @ptr2 null 0 #holding.text1 @ptr1fetch c2 into @ptr2, @xendclose c2deallocate c2endThe #holding table contains the fields that i want to concatenate andthe search table is the resulting table. This example would loopthrough search and find id 1 in search and then append another fieldmatching id 1 in holding then move onto the next field in turn goingthrough the whole table.i.e.search holding result after each loopid text id text1 abc 1 def abcdef2 ghi 2 jkl ghijklWhen I run this, some of the records concatenate properly but most dontwith the same text being appended to the end of searchterms. i.e loadsof results will end up with jkl tagged onto the end. I can't figure outwhen my loop is falliing over!!! Can anyone help?Dan
I keep receiving the following error whenever I try and call this function to update my database.
The code was working before, all I added was an extra field to update.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'WHERE'
Public Sub MasterList_Update(sender As Object, e As DataListCommandEventArgs)
Dim strProjectName, txtProjectDescription, intProjectID, strProjectState as String Dim intEstDuration, dtmCreationDate, strCreatedBy, strProjectLead, dtmEstCompletionDate as String
Dim myConnection As New SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("connectionstring")) Dim cmdSQL As New SqlCommand(strSQL, myConnection)
Forgive the noob question, but i'm still learning SQL everyday and was wondering which of the following is faster? I'm just gonna post parts of the SELECT statement that i've made changes to:
INNER JOIN Facilities f ON e.Facility = f.FacilityID AND f.Name = @FacilityName
OR
WHERE f.Name = @FacilityName
My question is whether or not the query runs faster if i put the condition within the JOIN line as opposed to putting in the WHERE line? Both ways seems to return the same results but the time difference between methods is staggering? Putting the condition within the JOIN line makes the query run about 3 times faster?
Again, forgive my lack of understanding, but could someone agree or disagree and give me the cliff-notes version of why or why not?
) ) ) ) ) AS timeType, Sum([2007_hours].Hours) AS SumOfHours from................
how can you convert it to sql syntax
I need to have a nested If statment which I can't do in sql (in sql I have to have select and from Together for example ( I can't do this in sql): select ID, FName, LName if(SUBSTRING(FirstName, 1, 4)= 'Mike') Begin Replace(FirstNam,'Mike','MikeTest') if(SUBSTRING(LastName, 1, 4)= 'Kong') Begin Replace(LastNam,'Kong,'KongTest') if(SUBSTRING(Address, 1, 4)= '1245') Begin ......... End End
end
Case Statement might be the solution but i could not do it.
This is the error it gives me for my code and then it calls out line 102. Line 102 is my buildDD(sql, ddlPernames) When I comment out this line the error goes away, but what I don't get is this is the same way I build all of my dropdown boxes and they all work but this one. Could it not like something in my sql select statement. thanksPrivate Sub DDLUIC_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DDLUIC.SelectedIndexChanged Dim taskforceID As Byte = ddlTaskForce.SelectedValueDim uic As String = DDLUIC.SelectedValue sql = "select sidstrNAME_IND from CMS.dbo.tblSIDPERS where sidstrSSN_SM in (Select Case u.strSSN from tblAssignedPersonnel as u " _ & "where u.bitPresent = 1 and u.intUICID in (select intUICID from tblUIC where intTaskForceID = " & taskforceID & " and strUIC = '" & uic & "'))"ddlPerNames.Items.Add(New ListItem("", "0")) buildDD(sql, ddlPerNames)
What I am trying to create a query to check, If recDT is not value or null, then will use value from SELECT top 1 recDtim FROM Serv. Otherwise, will use the value from recDT. I have tried the below query but it doesn't work. The error says, Incorrect syntax near the keyword 'SELECT'.Incorrect syntax near the keyword 'else'.1 SELECT 2 case when recDT='' then SELECT top 1 recDtim FROM Serv else recDT end 3 FROM abc 4 Anyone can help? Thanks a lot.
Hi, i am trying to write a mulitple sql statement. basically i have 5 fields to search:
User ID FirstName LastName Department Site i would like to search the records of the database with any of the fields above, so a user can specify a last name of "smith" and a department of "finance" which would return all the smiths in the finance department. or if a user enters "john" all the johns from any department or site would appear. How would the sql statement go like for this? and could i bind a tableadapter to a datagrid to view the results? Any help would be appreciated. Thank you.
Hello, I have at sp that return a value:set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go ALTER PROCEDURE [dbo].[sp_getLastActivityDate] ( @userid nvarchar(256)
) AS DECLARE @ret nvarchar(256) SET @ret = (SELECT CAST(LastActivityDate AS nvarchar) FROM aspnet_Users WHERE UserName = @userid) RETURN @ret The sp returns a nvarchar. How can i write the syntax in C# to grab the value in @ret? // Tomas
I'm a 3GL guy not familiar with SQL that much. What I try to add a record to shopping cart and assign a line number for each record. If the same item already exist, instead of adding a new line I'd like to add to existing line. I use to following code and I got two lines created even I was only adding the very first first. The following are the code I wrote, would anyone please give some hints. Thx.
ALTER PROCEDURE dbo.AddItemToCart ( @Cart nvarchar(50), @ItmID int, @Qty int, @ItmTyp char ) As
Declare @AllItmCount Int SELECT @AllItmCount = Count(ItmID) FROM ShoppingCart WHERE Cart = @Cart
IF @AllItmCount = 0 /*new shoppong cart*/ INSERT INTO ShoppingCart ( Cart, Qty, ItmID, ItmTyp, Line ) VALUES ( @Cart, @Qty, @ItmID, @ItmTyp, 1)
ELSE /*some item entered */
DECLARE @CountItems int
SELECT @CountItems = Count(ItmID) FROM ShoppingCart WHERE ItmID = @ItmID AND Cart = @Cart AND ItmTyp='R'
IF @CountItems > 0 /* same item entered before then add together */
UPDATE ShoppingCart SET Qty = (@Qty + ShoppingCart.Qty) WHERE ItmID = @ItmID AND Cart = @Cart AND ItmTyp='R'
ELSE /* Find the last line number */
Declare @LastLine Int SELECT @LastLine = Max(Line) FROM ShoppingCart WHERE Cart = @Cart
Hi all, I'm trying to build a simple forum. I want to display a list containing the forum names and last post date and last post author. I can view the date, but can't figure out a way to see the author. Here's the query i use: SELECT ForumID, ForumTitle, ForumDesc, ForumTopics, ForumReplies, (SELECT MAX(AddedDate) FROM (SELECT ForumID, AddedDate, Author FROM dbo.Forums_Topic UNION ALL SELECT ForumId, AddedDate, Author FROM dbo.Forum_Reply) AS dates WHERE (ForumID = dbo.Forums.ForumID)) AS ForumLastPostDateFROM dbo.Forums Any suggestion on how to show the author of the last message as well? Thanks in advance.
I am trying to create a view, but I am having trouble with the syntax (go figure!). It seems that as I reference more and more tables, my result set becomes smaller. For example, I want to return the state for all my customers then everything is fine, but when I want the state plus the site type (home, office, etc.) then I return fewer results. What is would be the correct syntax to use to return all the rows even if some of the columns have NULL?
SELECT TimeZone.LongZone, SiteMain.SiteNumber, SiteType.SiteTypeDescription FROM SiteType INNER JOIN TimeZone ON SiteType.id = TimeZone.id INNER JOIN SiteMain ON TimeZone.id = SiteMain.TimeZone AND SiteType.id = SiteMain.SiteType
I have some problem for construction Sql statement to execute in asp pages. In the table the data is stored in such a way that Worknote Id,IncidentId, SeqNo , Desc1,Desc2. 1111 2004 1 - Test1 Test2 2222 3000 1 - Test1 Test2 2222 3000 2 - Test3 Test3
I want to take the maximum of IncidentId (3000) and concatinate the description (Test1 TEst2 Test3 Test4)
I dono how to construct SQl to fetch records . I tried some way , it gives only the last row.
SELECT iWorkNoteID, SeqNum, vchWorkNote1, vchWorkNote2 from incidentworknote where iWorkNoteID = (Select max(iWorknoteID) from incidentworknote where iIncidentID = " & iIncidentId & ")"
I have a sql database which is not a backed up copy.....just a copy of the dbf file. I have tried everything in the enterprise manager to get the file re-introduced to no avail. I was told that you could execute the DB in the query analyser with the following
execute sp_attach_db @filename
but it does not like the syntax....can anyone please help.....
is it posible to run one sql query to check 20 tables to find a value? Let say i have 20 tables e.g. table1, table2, table3 e.t.c all have a column call import_instance_ID what sql statement do i run to check all tables where import_instance_ID = 2 ?? can someone help me with the syntax pls.
Excuse my ignorance. I have been reading and studying this stuff but still some questions.
Table Datatest Table B ID Q1 Q2 Output ID Field1 Field2 1 Y N 2 Y Y 3 N N
Everytime someone adds a record to Table Datatest I want that ID automatically added to Table B. What is the best way to do that? Is this were I use a trigger and an update or is there an easier way? Also case expressions again. How do I add the results from a case to the same table using a trigger?
Like: 100 for ID 1 223 for ID 2
SELECT ID, CASE WHEN Q1 = 'Yes' THEN 100 ELSE 0 end + CASE WHEN Q2 = 'Yes' THEN 123 ELSE end as Output, FROM Datatest
If I want to see a description of a specific tiem I do this:
select description from items,customer where customer.id = 1 and customer.item1 = items.id
That works fine but how do I dom if I want to have the dexcription on all three items ?: I tried select description from items,customer where customer.id = 1 and customer.item1 = items.id or customer.item2 = items.id or customer.item3 = items.id
Hello members, I have a trouble in retrieve correct query by SQL syntax. Ok I have use
SELECT * FROM tableOne WHERE UserID = 'mugun' AND First_Name LIKE '%tom%' OR Last_Name LIKE '%tom%' ORDER by First_Name ASC
Ok the probem is lets say, we have name TomCruise in our DB in First_NAme and Last_Name column. It return a correct value which is TomCruise. But if we change the syntax like this:
SELECT * FROM tableOne WHERE UserID = 'mugun' AND First_Name LIKE '%tomcruise%' OR Last_Name LIKE '%tomcruise%' ORDER by First_Name ASC
There is no result for the above statement. Why? Please help me . Thanx in advanced.
Here is the scenario: Table A has customer info (name and address)
Table B is a phone log table...a new row is created for each new call. In the table is a Date (when the customer was called) and a column named 'stage' that will be filled out either with the word 'follow up', 'dead', or null.
So the relationship from Table A to B is 1 to many, respectively.
I want to ask the two tables this question: Give me name and address (from Table A) and LATEST date customer was called, but ONLY if the 'stage' column says 'follow up'.
Here is the problem...Dr. Jones has three rows in Table B, his latest call was today, but stage is set to 'dead'. His second line in the table was called yesterday, with the designation of 'follow up'.
When I run my query, I pull out the row from yesterday, since it meets the criteria of 'follow up'....but this is wrong, as I only want the latest designation of 'follow up' IF its the lastest date for this customer.
Here is my syntax: SELECT DISTINCT MAX(tableB.date) AS latestdate, tableA.CONTACT, tableA.ADDRESS1, FROM tableB INNER JOINTableA ON TableB.ACCOUNTNO = TableA.ACCOUNTNO GROUP BY tableA.CONTACT, CONTACT1.ADDRESS1 HAVING (tableb.stage = 'follow-up')
Table A has three columns (aaa1, aaa2, aaa3) Table B has three columns (bbb1, bbb2, bbb3)
Common field is aaa1 = bbb1
I write a query that retrieves 3 rows out of table a (select aaa2, aaa3 from table a where (aaa2 = green) and (aaa3 = yellow)) ---------------------------------------------------------- When I now create a left outer join onto Table b, and add one more additional criteria to the where exisiting ones(aaa2=green,aaa3=yellow) which is bbb2='white', I expect to at least see my original three rows of data (since of my left outer join), but now only receive 2 rows of data, since the third row does not have bbb2 as white.
Im confused...I was expecting to see three rows of data, with the bbb2 column being null for the third row....but instead I only get two rows of data...how can I write my query that will give me what I expected ?