Hi all - I have posted inquiries on this rather vexing issue before, so I apologize in advance for revisting this. I am trying to create the code to add the parameters for two CheckBoxLists together. One CheckBoxList allows users to choose a group of Customers by Area Code, the other "CBL" allows users to select Customers by a type of Category that these Customers are grouped into. When a user selects Customers via one or the other CBL, I have no problems. If, however, the user wants to get all the Customers from one or more Area Codes who ALSO may or may not be members of one or more Categories; I have had trouble trying to create the proper SQL. What I have so far:
Protected Sub btn_CustomerSearchCombined_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_CustomerSearchCombined.Click
Dim CSC_SqlString As String = "SELECT Customers.CustomerID, Customers.CustomerName, Customers.CategoryID, Customers.EstHours, Customers.Locality, Category.Category FROM Customers INNER JOIN Category ON Customers.CategoryID = Category.CategoryID WHERE "
Dim ACItem As ListItem
Dim CATItem As ListItem
For Each ACItem In cbl_CustomersearchAREA.Items
If ACItem.Selected Then
CSC_SqlString &= "Customers.AreaCodeID = '" & ACItem.Value & "' OR "
End If
Next
CSC_SqlString &= "' AND " <-- this is the heart of my problem, I believe
For Each CATItem In cbl_CustomersearchCAT.Items
If CATItem.Selected Then
CSC_SqlString &= "Customers.CategoryID = '" & CATItem.Value & "' OR "
End If
Next
CSC_SqlString = Left(CSC_SqlString, Len(CSC_SqlString) - 4)
CSC_SqlString &= "ORDER By Categories.Category"
sql_CustomersearchGrid.SelectCommand = CSC_SqlString
End Sub
Any help on this is much appreciated, many thanks --
I have a tsql where I need to do a patindex on a variable and check if a record exists to meet the where clause for a IF statement below. What am I doing wrong
declare @l_orderid int set @l_orderid = 18 declare @l_SIGShort varchar(20) set @l_SIGShort = '~KOP~' -- KOP Orders print patindex ( '%~KOP~%', @l_SIGShort) if patindex ( '%~KOP~%', @l_SIGShort) <> 0 and (if exists (select * from orderoptions where orderid = @l_orderid and ordertype = 'KOP'))
Greetings, I seem to be getting a problem during installing SQL 7.0 over the SQL 7.0 beta. It tells me that there are ODBC components need to be upgraded and they are read only ... I can find no way of changing this.
Alternatively if I remove the beta and then install the proper version, will all the old db created under the beta still be recognised ?
Kris Klasen
Act. Manager, Data Warehouse Project Information Management Branch Department of Education
I have been told that simply stopping the SQL server service and backing up the data directory is all I have to do to do a backup of my data. Is this accurate?
Hello: a nice simple question (I hope). Is there a MS SQL equivilant to PROPER (string) which would return "Fred Bloggs" from "FRED BLOGGS" and equally from "FrEd bLoggs" ? I cant find such ....
I am no stranger to Databases, I worked a lot with MySQL but never really cared about proper DB design as long as it worked. Now I am playing with SQL in a ASP.NET project and want to get things done the right way.Let's say I have a Movies database. My movies can have multiple genres so I set my tables up like this:
[Movies] MovieID MovieName MovieRelease
[code]....
Is this the proper way of doing things? The problem with this is when I want to enter a record manually I have to know the ID of the movie and the ID of the Genres of the movie. And what about naming conventions? By default the identifier is always Id, from my MySQL experience I liked naming it like the table, same goes with other columns. This is my T-SQL code for above tables in VS-2013.
CREATE TABLE [dbo].[Movies] ( [MovieID] INT IDENTITY (1, 1) NOT NULL, [MovieName] VARCHAR (50) NOT NULL, [MovieRelease] NUMERIC (18) NOT NULL, CONSTRAINT [PK_Movies] PRIMARY KEY CLUSTERED ([MovieID] ASC)
I read some questions where questioners ask "Sometimes client gives data where dates are expressed as float or integer values. How do I find maximum date?".
Ex March 02, 2006 can be expressed as 02032006.0 020306 2032006 20306 020306.0000 2032006 Assuming the values are expressed in dmy format
The possible way is convert that value into proper date so that all types of date related calculations can be done Create function proper_date (@date_val varchar(25)) returns datetime as Begin Select @date_val= case when @date_val like '%.0%' then substring(@date_val,1,charindex('.',@date_val)-1) else @date_val end return cast( case when @date_val like '%[a-zA-Z-/]%' then case when ISDATE(@date_val)=1 then @date_val else NULL end when len(@date_val)=8 then right(@date_val,4)+'-'+substring(@date_val,3,2)+'-'+left(@date_val,2) when len(@date_val)=7 then right(@date_val,4)+'-'+substring(@date_val,2,2)+'-0'+left(@date_val,1) when len(@date_val)=6 then case when right(@date_val,2)<50 then '20' else '19' end +right(@date_val,2)+'-'+substring(@date_val,3,2)+'-'+left(@date_val,2) when len(@date_val)=5 then case when right(@date_val,2)<50 then '20' else '19' end +right(@date_val,2)+'-'+substring(@date_val,2,2)+'-0'+left(@date_val,1) else case when ISDATE(@date_val)=1 then @date_val else NULL end end as datetime ) End
This function will convert them into proper date select dbo.proper_date('02032006.0') as proper_date, dbo.proper_date('020306.000') as proper_date, dbo.proper_date('02032006') as proper_date, dbo.proper_date('020306') as proper_date, dbo.proper_date('20306') as proper_date, dbo.proper_date('020306') as proper_date
Apart from converting integer or float values to date, it will also convert date strings to date Select dbo.proper_date('March 2, 2006') as proper_date, dbo.proper_date('2 Mar, 2006') as proper_date, dbo.proper_date('2006 Mar 2') as proper_date, dbo.proper_date('2-Mar-2006') as proper_date, dbo.proper_date('3/02/2006') as proper_date, dbo.proper_date('02-03-2006') as proper_date, dbo.proper_date('2006/03/02') as proper_date, dbo.proper_date('March 2006') as proper_date, dbo.proper_date('2 Mar 2006') as proper_date
What is the proper way to return the identity of a newly inserted row from a stored procedure? Using a return value or a select statement? (I guess as an output parameter should also be considered...) As in
RETURN SCOPE_IDENTITY()
or
SELECT SCOPE_IDENTITY()
What are the pros/cons of using one approach over the other?
I have two xml queries that take long: the 1st query takes about 5 minutes (returns 700 rows) and the 2nd query takes about 10 minutes (returns 4 rows). The total rows in the table is about 2 million. There are three secondary indexes: Property, Value and Path in addition to the clustered index on CardID and Primary XML index. Here is the table definition:Â
CREATE TABLE [dbo].[Cards] ( [CardId] [int] NOT NULL, [Card] [xml] NOT NULL, CONSTRAINT [PK_dbo_Cards_CardId] PRIMARY KEY CLUSTERED ([CardId] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
[code]...
Looking at the execution plan, the query uses the Primary XML Index even if I add any of the secondary xml indexes. My question is why does not the optimizer use the Property 2ndary index instead of the Primary XML Index? Microsoft recommends that creating a Property index for Value() method of the xml datatype would work to provide a performance benefit. What would be another alternative to make the query run faster?
Hello, I have one package that seems to have continuous problems with memory. As of right now it loads a little over 1 million records. I tried leveraging the property, BufferTempStoragePath, but I don't seem to have the right path name. What sort of path do you put there? File? Folder? If it is a file, what sort of file should it be... text, dat, xml? If someone could point me in the right direction it would be greatly appreciated. Thanks.
PS: Below are the error messages I am getting: [DTS.Pipeline] Information: The buffer manager detected that the system was low on virtual memory, but was unable to swap out any buffers. 4 buffers were considered and 4 were locked. Either not enough memory is available to the pipeline because not enough is installed, other processes are using it, or too many buffers are locked.
[DTS.Pipeline] Error: The buffer manager cannot create a temporary storage file on any path in the BufferTempStoragePath property. There is an incorrect file name or no permission.
I'm developing an app that uses Service Broker queues to allow a customer to create "events" that fire using a timer or a query notification. When these events fire, a message is sent to a Service Broker queue for processing. Because there is much managed code involved in processing these messages, I decided to use the External Activator application and an Event Notification to process these messages. My question is "what is the difference between using the External Activator application to launch another application (which simply RECEIVEs a message from the target queue and processes it) and creating a windows service that simply monitors the target queue (with a WAITFOR = -1 clause) and processes it?"
I guess I'm not sure how using the QUEUE_ACTIVATION Event Notification is really helping me.
I have a .csv file that lists date like this: "20070522", no hyphens or spaces. In the file connection manager I have the column defined as string. The database column is a datetime.
When I attempt to load the file to the table, I get this error:
[OLE DB Destination [9]] Error: There was an error with input column "effective date" (155) on input "OLE DB Destination Input" (22). The column status returned was: "The value could not be converted because of a potential loss of data.".
My question is, what do I need to do to this column so that I can load it into the database?
Am I using the cursor feature properly here? Â -- of course there would be actual processing (replacing a while loop) going on and not simple print statements.
Declare @BadgeNumber varchar(20), @name varchar(100), @phone int, @status varchar(25) Declare cursor Cursor For Select jt.BadgeNumber, tj.Name, jt.Phone, zt.status From employees jt join employeestatus zt On jt.id = zt.id
I need to concatenate two date fields so they appear in a drop-down list like this: 8:00 AM - 10:00 AM I'm using MS SQL 2005 and my query looks like this: SELECT ClinicTimesID, ClinicID, (CTStartTime + ' - ' + CTEndTime) AS TimeSlot FROM Clinics_Times WHERE (ClinicID = 1) and I get this error: Msg 242, Level 16, State 3, Line 1 The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. Can I strip out the date so that only the time appears or is it even possible to concatenate these fields? If so, how? Thanks!
Hello all, I'm trying to combine two columns of data into a third column using a formula on the thrid column. Each of the columns could contain nulls and each of the columns could contain padding after or before the data. I'm trying to use the following formula yet SQL is throwing an error. Can someone provide another set of eyes to check this out? ISNULL(LTRIM(RTRIM([user_Define_4a])),’’) + ISNULL(LTRIM(RTRIM([user_Define_1])),’’) Thanks
I am completely new to SQL and I have some syntax questions. I am trying to concatenate 4 fields and some padded constants to form a new key field to perform joins. The result should be a twelve character field without spaces. My problem is that the current fields use spaces as place holders and I need to replace the spaces with ‘0’.
1st ‘0’ (constant) 2nd, 3rd, and 4th, from [RD_ID] (without the suffix) 5th and 6th from [RD_ID] suffix or replace spaces with ‘00’ 7th 1 or 2 from [RDWY_ID] 8th Z from [MLGE_TYPE] or replace space with ‘0’ 9th 1 – 9 from [OVLAP_MLGE_CD] or replace space with ‘0’ 10th ‘S’ (constant) 11th ‘0’ (constant) 12th ‘0’ (constant)
Results should resemble 0001CQ100S00 or 000100100S00
Col1 Col2 Col3 --------------------------------------------------------------------------- Andrews S 93845877712 P Sylvia 9999876669 J Bill K 7657654677 L
I need the output like this Col1 Col2 Col3 -------------------------------------------------------------------------- AndrewsS 93845877712 P Sylvia 99999876669 J BillK 76576546677 L
The character on the left of Col2 has to be joined to Col1 and character on the right of col2 has to be joined to Col3. Can anybody suggest a query for this.
Hi everyone, I'm creating a ASP.NET 2.0 web application utilizing sql server 2000 as a database. My problem revolves around multiuser acces with long running processes. Some of the pages in the application have long running processes against large tables in the database, lets say that take 2minutes to complete. My problem is how do I utilize ado properly in the rest of my application to display a message to users who may try to access data associated with a table while in the midst of one of its long running processes? For instance I would like to notify the user that "Table X is currently locked, please try again in a few minutes".Do I catch sqlException and examine the .Number property? Any insight is appreciated. Thanks.
I'm trying to handle a stored procedure parameter. What needs to happen is that a particular statement shouldn't be executed if the parameter is empty. However, when I try it I get the following error:Cannot use empty object or column names. Use a single space if necessary.So, what's the correct way of doing the following?IF @filename <> ""BEGIN UPDATE Experimental_Images SET contentType = @contentType, filename = @filename WHERE (id = @iconNo)END
I'm having an issue getting the data how I want it from SQL to then populate my dropdownlist. I have a table called SALES_BUDGR_TBL that contains alot of columns but the ones I'm focusing on are SRCURM (Month) and SRACYR (Year). What I need to do is populate a dropdownlist and show the current month first and then work backwards. The data in the dabase goes back 14 months. I created a reference table called MonthOrder that has 3 columns, MonthID, MonthName and MonthAbrv. I did this so I have a way of saying which month belongs where when sorted. Here is the select statement I currently have. I'm joining the tables and then I want to Order by the MonthID, but I would also like it to show the 2006 records first, then goto 2005, starting with December and going down of course. Is there anyway to do this? My Select and Results are below... SELECT DISTINCT SB.SRCURM, SB.SRACYR, MO.MonthID, MO.MonthName FROM SALES_BUDGR_TBL SBINNER JOIN MonthOrder MO ON SB.SRCURM = MO.MonthAbrvORDER BY MO.MonthID DESC DEC 2005 12 DecemberNOV 2005 11 NovemberOCT 2005 10 OctoberSEP 2005 09 SeptemberAUG 2005 08 AugustJUL 2005 07 JulyJUN 2005 06 JuneMAY 2005 05 MayAPR 2005 04 AprilAPR 2006 04 AprilMAR 2006 03 MarchFEB 2005 02 FebuaryFEB 2006 02 FebuaryJAN 2006 01 January If I say only get 2006 records it works but I need a better way to do this.
I am getting the following error. “The user instance login flag is not supported on this version of SQL Server. The connection will be closed.� Background i created a site on my development machine, and every thing worked, this computer is running sql EX. I uploaded the site to the production server (running sql 2005 standard) and changed the connection string (i have used this connection string with other dB’s to display data only, and it works) but i tried it with the ASPNETDB.mdf in the AppData folder and i get the above message.
Do i have to set some special permissions in the db for it to work. I need to be able to insert, update, and delete in this app.
I'm working in vb.net and want to use a stored procedure to insert all employees from one db into my db. I can insert one by one, but I would like to get them all in without looping.
How would I do this? I've tried bulk insert, but I keep getting syntax errors; I've read the books online, but don't quite understand what they mean. I don't want to use DTS, should I?
Good Morning,I have a person table with personID. I have a personRate table withpersonID, rateID, and effectiveDate.I need to select fields from personRate, but I want the fields from theproper record.I need the one child record that has the most current date of the largestrateID.For example a person may have many rate records. I need the record that hasthe most current date of the largest rateID they have. Does that makesense?I am making a view that has data from both tables. I need to display themost current rate info.Any ideas? TIA ~ CK
I have created a Web service and I want to call a single method from it to extract data. For this reason I use the SSIS "Web Service Task" . The problem is that the xml output file from the web service task does not look in the proper way. When I invoke my web service method in the browser the result looks like the following: <?xml version="1.0" encoding="utf-8" ?> - <ArrayOfBooking xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/"> - <Booking> <BookingDate>2007-04-12T15:19:01.6736072+03:00</BookingDate> <FlightDate>2007-04-12T15:19:01.6736072+03:00</FlightDate> </Booking> - <Booking> <BookingDate>2007-04-12T15:19:01.6736072+03:00</BookingDate> <FlightDate>2007-04-12T15:19:01.6736072+03:00</FlightDate> </Booking> </ArrayOfBooking>
but when I use the web service task , the xml file produced, looks like the following:
My problem is that I cannot create a xsd schema for the xml file output from the "web service task", and because of this I cannot insert the data in the xml file into the Database, because the xsd schema is reqired by the XML Source which I use in my DataFlow task for inserting the data. Do you have any ideas how to solve this strange problem?
I am pretty new to the database administration and was wondering if i could get some advice here so i have a head start.
Unfortunalety i have came to the conclusion the hard way that the SQL Agent on Ms SQL 2000 doesnt work properly when it comes to database backups. I discovered that the backups it creates and it claims that are performed succesfully do not work.
So i was wondering what would be the proper way to go in creating a backup of a highly critical database. The database is in MS SQL 2000. I am not required to have the application roll over to the backed up data in case the main one crashes. But it is absolutely necessary to be able to restore the databse to a most recent working copy. So i guess performing a backup once a day would do. Loosing data from a day would not be such a big deal since i have other ways of restoring that days data, as long as i have the full database up to the previous day.
I was looking at database mirroring but that is not available with sql 2000.
Also i though of as a possibility to run a replication on the SQL 2000 database and replicate to SQL 2005 database which aparently has got the SQL agent working properly.And then run the agent on the SQL 2005 database which would backup the copy daily?
Any advice is apreciate and if there are any white papers or books i could look at that would be great.
Hi All, I've been trying to create a dynamic query using the 'Like' clause and '%'. my code snippet looks like this: while (@@FETCH_STATUS = 0)begin set @likeString = @likeString + ' item_Text LIKE ''%'+@word+'%'' OR ' fetch next from theLike into @word end
-- strip off last ORset @likeString = ltrim(rtrim(substring(@likeString, 0, (len(@likeString) - 3))))-- ================================================-- create query to find keywords in the index and store in temp table-- ================================================set @query = 'INSERT into #resulttable (itemcount, item_id) SELECT COUNT(d.item_id), d.item_id FROM tp_index_details AS d INNER JOIN tp_index ON d.idx_id = tp_index.idx_id 'set @query = @query +' WHERE (d.idx_id IN (SELECT idx_id FROM tp_index AS i WHERE ( 'set @query = rtrim(@query) + @likeStringset @query = @query + ' ) AND (subscription_id = 1000))) GROUP BY d.item_id ORDER BY d.item_id DESC' The problem is the @query string gets truncated. My question is how to get the quotes around '%' variables to work in a string? Thanks for any help! regards Davej