I am new to the topic T-SQL. I am trying to use T-SQL to merge the content of two tables (table1 and table2) into one table making sure there are no duplication.
I wonder if any body can let me have a simple code.
Hey guys what would be the easiest way to create a report of value changes for particular records from one day to the next..... ? Any suggestions would be greatly appreciated....
Hi there! can anyone help me out??? I need to compare a date from the database and the system date which will be coded in a store procedure in SQL... HELP!!!!!
I have a table with a field with a bit datatype. When I execute the stored procedure line if @bitvalue = 1 begin ... and the value is passes as 0 the statements beneath the begin execute. What am I doing wrong?
Is there a way to compare two similar tables? I'm more interested in finding out if the data content is exactly the same or not between the two tables.
We are converting our project into new version. They have done lot of changes in new version including normalization/denormalization. I need to compare the old and new database. Do you have any standard script or procedure like SQL Compare software?. Let me know what are the possibilties we need to check. Your help appreciated. Thanks, Ravi
Assuming a table with a column defined char or varchar. I have a SQL query like this :
Select * from table1 where column1='Building'
It returns the same result that
Select * from table1 where column1='BUILDING'
It is my understanding SQL Server (verison 7 or 2000, I tried on both) is lower/capital insensitive by default when it is installed. If I want SQL Server to be case-sensitive with my char or varchar columns, where can I set it?
Is it at database level or server level I can find this setting . What is the setting that control it?
Best Regards, Alain Gagne, Lead DBA gagnea@msagroup.com
Morning! Folks, i want some links where i could find healthy stuff regarding New Features and Compliance levels, performance comparisons, TPC tests etc about SQL 2000 and Yukon specially. I've to submit a document regarding Top database features that shall be used for a Medical-Billing Software in plan.
I have two tables that I am needing to link by the tables date field. In one table the date field is defined as varchar(23). The time for this field is always zeros. Example: '2005-12-27 00:00:00.000'
The other table is defined as datetime, and it does have the date and time in this field. Example: 2005-12-27 08:00:35.000
The problem i am having is 2005-12-27 00:00:00.000 does not = 2005-12-27 08:00:35.000.
Because I will never have more than one record on the same date I would like to be able to only compare the date. Example 2005-12-27 = 2005-12-27
Since the fields are 2 different field types, this is giving me a problem. Could someone please help. I have tried everything I know to do.
What I really need is the a way to format the datetime fields date into a string such as '2005-12-27'.
In management studio, is there a way to compare databases side by side? Or would anyone know of any freeware out there that would do such a task? :beer:
I am doing this 2 queries, they get data from the same tables in a very different way. The new way is a lot faster but of course there are problems. There are some discrepancies in the results. Both queries produce results with more than 200.000 rows. Second one has ca. 100 rows less than the first one and some of the results are wrong (most are correct though).
My question is how do I find the differences. I did the left outer join when column a.result != b.result (lines are defined by date and ID so they should be unique).but the join gives me problematic results (some are not different at all, some differences are not in the result).so how do I find the differences between 2 queries, including missing results/rows?
I have an Employee table with 3000 records and an Excel file having themodified data of those emplyoees. Some of the data of Excel may be sameas that of table data but some may differ. EmpId is the unique field.Other than this field, other fields of Excel may have modified data.Ineed to compare the data from SQL Server table with Excel Data.I decided to write a VB Program having two recordsets,one for SQLServer and other for Excel and compare each field's value. If themodified value is found then update that to table. Is there any way tocompare in SQL Server itself?Madhivanan
I am looking for some papers/information that compare relationaldatabases such as oracle, mysql, sql server etc. I am particularlyinterested in their features such as locking mechanisms, integrityconstraints, views... Anyone know where I can find the information?Thanks,Susan
I'm in need of a sql query that I'm not sure is possible. Here is anexample of how it's laid out.employee ID Job class Last Change Date12345 x 2/1/200412345 y 1/15/200412345 z 1/1/2004We know that this person is in job class 'x' because it's the mostrecent change. Is there a way to write a query that will exclude thelines 'y' and 'z' because they are currently incorrect?I would appreciate any help I could get. Thanks
As many of you know I've been hunting down a SQL CE alternative / embedded DB that is easily portable among handhelds.
It turns out, that without paying for some other DB, there really aren't any good ones... Unless you go GPL, and the interpretation of GPL that most are using is that your code too is GPL even though you may only Dynamically Link to their app. I think this is likely wrong, but none the less I'm back here yet again.
What I'm looking for this time is a definition of how SQL Server CE is implemented, how it differs from a full blown DB, etc, so I can more thourally explain "why SQL CE" is an embedded DB, and how it isn't the full blown SQL Server that has a bad reputation with some.
My guess is:
SQL Server CE is implemented via DLL. There aren't sockets etc to allow you to connect, and it operates more like an advanced hash on the file system.
Please correct me if i'm wrong, or... send me a link where I can further research. Also, if you have another embedded DB as a suggestion, that's free of course, please point it my way.
I'm trying to do a comparison of 2 data sets. Basically what I want is: 'where event date from event number -24 is earlier than the event date for event number -13'
To get the eventdate for the eventno's, I have the following 2 queries:
select eventdate from caseevent, cases where eventno = -24
select eventdate from caseevent, cases where eventno = -13
So what i'm trying to say is: I want it so that the value of the first query is compared to be LESS than the value of the second query...
Hi, I have table with four fields ID, Date1, Date2,Date3,Date4. Dates are in numeric farmat like 20070927. How can i get largest date (from date1 to date4) on each row. Please suggest query. Thanks
Not sure if possible but I need to produce a monthly TOP 10 Ticket Category report which I retrieve with:
SELECT TOP (10) Category, COUNT(Category) AS Count FROM table WHERE (DATEDIFF(mm, open_date, GETDATE()) = 1) GROUP BY Category ORDER BY Count DESC
Now I need to know how many tickets there were for those same categories in the previous month so I want my result set to look somewhere along the lines of: Catagory - Count Month - Count Previous Month
I have 2 CLR Functions, both do the same thing, and they seem to perform the same based on testing. I am working on building examples for the web, and considered putting both up but I think the use of the Regular Expression is more of a best practice. Any thoughts on this?
Code Snippet using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; public partial class UserDefinedFunctions {
[Microsoft.SqlServer.Server.SqlFunction] public static SqlBoolean IsValidIP(string IPAddress) {
int i; string[] ipParts; if (IPaddress == string.Empty) {
return false; } else {
ipParts = IPaddress.Split('.'); for (i = ipParts.Length - 1; i >= 0; i--) {
try {
int i = int.Parse(ipParts[i]); if (i > 255) return false; } catch {
return false; } } return true; } } };
Regular Expression Function:
Code Snippet using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Text.RegularExpressions; public partial class UserDefinedFunctions {
[Microsoft.SqlServer.Server.SqlFunction] public static SqlBoolean IsIP(string IPAddress) {
// IP Address must be 4 part with each part 3 digits and less than 255. Regex regex = new Regex(@"^((2[0-4]d|25[0-5]|[01]?dd?).){3}(2[0-4]d|25[0-5]|[01]?dd?)"); return (SqlBoolean)regex.Match(IPAddress).Success; } };
My only beef with the Regular Expression function is that Regular Expressions are often over the head of many people. I could provide both examples, and cross link them, but I am not sure about that. Any opinions?
Hi,i need a column in a SELECT statement which returns always "true" (As a boolean value, not as a string)so I first tried SELECT field1, field2, true AS field3but this is not working. If I use "0 AS field3" this returns fine the 0, but this is not a boolean but a int.I also tried to make something like     "0 = 0 AS field"but also errors. In that context I discoverd that I could not compare values in the select field - I can use +,-+,* ... for having something like "2 * field1 AS field3" but I'm not clever enough to figure out how I would have a field "field1 < 12 AS field3" (ok I would use CASE, but I need the boolean return value...)Any ideas?Thanks in advance, Klaushow could I write something
I have StratDateTime and EndDateTime fields in the table. I need to compare this two datetime fields and find seconds. I can use DateDiff but there are the following exceptions: 1. Exclude seconds coming from the date which are Saturday and Sunday 2. Exclude seconds coming from time range between 7:01pm and 6:59am 3. Exclude seconds coming from Jan 1st and Jul 4th. How can I do this?
I remember at some point I had some problem with this issue and I couldn't find something that suites a newbie. The point that I was missing was that I couldn't pass the string representation of the date value to a query string. The key is to convert the string date to its equivalent datetime or smalldate . For example imagine you'd like to select all Employees who where born on a specific date stored in a variable called myDate: the BirthDay column in our Employee table has type smalldatetime ---------------------------------------------- string myDate = @"06/06/1978"; .... SqlCommand comm = new SqlCommand("SELECT * FROM EMPLOYEE WHERE [BirthDay] = Convert(smalldatetime,'" + myDate + "', 103))"; .... ---------------------------------------------- Make suer that you don't miss single quotes around value of myDate in your query string. For more info regrading the Convert function look at: http://msdn2.microsoft.com/en-us/library/ms187928.aspx
Hi,The problem here in hand is comparing the month & year ranges rather than the entire date. I am passing a start month and start year along with the end month and end year, now the query that i have written does not seem to be appropriateMy Query:MONTH(Date_Added) BETWEEN @StartMonth AND @EndMonthAND YEAR(Date_Added) BETWEEN @StartYear AND @EndYearFor some reason this works fine if i specify the startmonth as 1 and endmonth as 12, whereas if i specify 1 and 1 it doesnot work. Can anyone help me by refining my query so that i can search a particular date within mm/yyyy and mm/yyyy. Thanks in advance.Santosh
Hi all, In the DB i have stored the username and password. i had stored 'am' as password and wen i use 'Am' to login, it wil redirect to my next page correctly.Can we do any string comparison for that? Normally how can this problem be solved? Try con.Open() cmd = New SqlCommand("select CompanyId,Password from CompanyDetails where CompanyId=" & uname & " and Password='" & pass & "'", con) Dim sdr As SqlClient.SqlDataReader = cmd.ExecuteReader If sdr.HasRows Then sdr.Read() Me.Session.Add("value", Val(txtuser.Text)) Response.Redirect("ViewDetails.aspx") Else Err.Text = "Invalid UserName/Password." End If Catch ex As Exception Err.Text = ex.Message Finally con.Close() End Try