I'm recently change my data table, I remove column and add a new column that define as identity = True and identity seed = 1, identity increment = 1.
When i tried to insert data to this table by STORE PROCEDURE i get this exception:
An explicit value for the identity column in table 'AirConditioner' can only be specified when a column list is used and IDENTITY_INSERT is ON.
I saw that i need to add this lines:
SET IDENTITY_INSERT [dbo].[AirConditioner] ON and finally OFF
I added and its still throw an exception...
My store procedure is attached as a picture
Hi,
I've got tqo queries:
First doesn't work:
select hotels.TargetCode as TargetCode from hotels
union all
select DuplicatedObjects.duplicatetargetCode as TargetCode from DuplicatedObjects where DuplicatedObjects.objectType=4
because I get error:
Cannot resolve collation conflict for column 1 in SELECT statement.
Second works:
select hotels.Code from hotels where hotels.targetcode is not null
union all
select DuplicatedObjects.duplicatetargetCode as Code from DuplicatedObjects where DuplicatedObjects.objectType=4
Structure:
Hotels.Code -PK nvarchar(40)
Hotels.TargetCode - nvarchar(100)
DuplicatedObjects.duplicatetargetCode PK nvarchar(100)
If I want to get a user that has the email address of '[email protected]', how do I pass that as a parameter in linq?
ie.:
var a = from u in Users
where u.Email = @email
Select u;
So this would be used in my method:
public static GetuserByEmail(string email)
Do I just pass in the variable or?
Hi All,
I have a table called Employee with EmpID,Salary,Name fields.
I want to get top two employees with maximum salary.
How can i write this query ?
I have found some similar posts, but I didn't find them useful. But I didn't know how to group them.
I would like to Sum 'No' and 'Not Set' to one row, and to lose 'Not Set' row.
So : 'No' = 'No' + 'Not Set'
I have something like this :
TEST TestCount Month
'Yes' 123 March
'No' 432 March
'Not Set' 645 March
'Yes' 13 April
'No' 42 April
'Not Set' 45 April
'Yes' 133 May
'No' 41 May
'Not Set' 35 May
....
And I would like something like this :
TEST TestCount Month
'Yes' 423 March
'No' 410 March
'Yes' 154 April
'No' 192 April
'Yes' 130 May
'No' 149 May
....
Can anybody help me with this, tnx in advance
So, MongoDB defaults to "AND" when finding records. For example:
db.users.find({age: {'$gte': 30}, {'$lte': 40}});
The above query finds users = 30 AND <= 40 years old.
How would I find users <= 30 OR = 40 years old?
eg:table
pkey --guid
annualpay
datefrom
dateto--if null means current record
percentannualincrease
percent annual increase will be calculated only if there is a difference in newly inserted and previously existing last differing value.
percentannualincrease =
([newannualpay-just previous pay(if different from current)]/newannualpay)*100
eg
newid(),5000,today,null,0--very first row
newid(),5000,today+1,null(*),0
newid,5500,today+2,null(*),?????????????--> need to be calculated before insert
*--insert will close the previous record by updating dateto=null to todays date
How can I do this stuff in a trigger???
What is wrong with the last query? Is it a bug or am I missing something?
This query returns 2 records (correct):
query = query.Where(Log => SqlMethods.Like(Log.FormattedMessage, "%<key>Name</key><value>David</value>%"));
This query returns 2 records (correct):
query = query.Where(Log => SqlMethods.Like(Log.FormattedMessage, "%<key>Name</key><value>%David%</value>%"));
This query returns 0 records (correct):
query = query.Where(Log => SqlMethods.Like(Log.FormattedMessage, "%<key>Name</key><value>av</value>%"));
This query returns 2 records (correct):
query = query.Where(Log => SqlMethods.Like(Log.FormattedMessage, "%<key>Name</key><value>%av%</value>%"));
This query returns 0 records (correct):
query = query.Where(Log => SqlMethods.Like(Log.FormattedMessage, "%<key>Name</key><value>v</value>%"));
This query returns 15 records (incorrect, should return 2):
query = query.Where(Log => SqlMethods.Like(Log.FormattedMessage, "%<key>Name</key><value>%v%</value>%"));
See this sample schema
Passenger(id PK, Name)
Plane(id PK, capacity, type);
Flight(id PK, planeId FK(Plane), flightDate, StartLocation, destination)
CREATE TABLE Reservation(PassengerId, flightId,
PRIMARY KEY (passengerId, flightId),
FOREIGN KEY (passengerId) REFERENCES Passenger,
FOREIGN KEY (flightId) REFERENCES Flight);
I need to define an integrity constraint that enforces the restriction that the number of passengers on a plane cannot exceed the plane’s capacity.
I have tried and achieved so far is this.
CREATE TABLE Reservation(
passengerId INTEGER,
flightId INTEGER,
PRIMARY KEY (passengerId, flightId),
FOREIGN KEY (passengerId) REFERENCES Passenger,
FOREIGN KEY (flightId) REFERENCES Flight,
Constraint check1
check(Not Exists(select * from Flight s, (select count(*) as totalRes from Reservation group by flightId) t
where t.totalRes > s.capacity ) )
);
I am not sure i am doing in right way or not.
Any suggestions?
I'm using Netbeans 6.8 to develop application using JSP. I'm able to work with it properly in my project guides system. But i'm unable to get the connection to database from my system.
It shows error unable to connect.
I have not changed any of the codes. How can I fix this error?
My algorithm is for a hit count, I am tring to not count for the same person twice if that person came to the site twice in a time internval (For example if he comes twice in 5 minutes, I want to count it as 1 for this person)
Here how my database looks like
UserIp UserId Date of user came
127.0.0.1 new.user.akb 26.03.2010 10:15:44
127.0.0.1 new.user.akb 26.03.2010 10:16:44
127.0.0.1 new.user.akb 26.03.2010 10:17:44
127.0.0.1 new.user.akb 26.03.2010 10:18:44
127.0.0.1 new.user.akb 26.03.2010 10:19:44
127.0.0.1 new.user.akb 26.03.2010 10:20:44
127.0.0.1 new.user.akb 26.03.2010 10:21:44
127.0.0.1 new.user.akb 26.03.2010 10:22:44
127.0.0.1 new.user.akb 26.03.2010 10:23:44
What I need to do is get number of distinct UserIPs from the table above that occured within a time interval. For example if I set the time interval for 5 minutes, and let say that is starts at
26.03.2010 10:15:44
Then I will get 2 as the results, since 1 distinct value between 10:15 to 10:20 and , 1 distinct value from 10:20 to 10:23,
For example if my interval is 3 minutes than the return result will be 3
Thanks.
Hi, i have 2 table
User (id, name, surname,cod)
UserNew (uid, uname, usurname, ucod)
The first table has data the second no.
I have to copy the data of the User table in the UserNew table.
I've tried with a insert query but uid (primary key) value changes.
How can i do to mantaince the same values?
thanks
Hi,
from front end application i am sending the value as 0.15 to data base (stored procedure) but it storing as 0 value . why ? please guide. I am usingf c# + asp.Net sqlserver 2008
SELECT EmployeeMaster.EmpNo, Sum(LeaveApplications.LeaveDaysTaken) AS LeaveDays
FROM EmployeeMaster FULL OUTER JOIN
LeaveApplications ON EmployeeMaster.id = LeaveApplications.EmployeeRecordID INNER JOIN
LeaveMaster ON EmployeeMaster.id = LeaveMaster.EmpRecordID
GRoup BY EmployeeMaster.EmpNo
order by LeaveDays Desc
with the above query, if an employee has no leave application record in table LeaveApplications, then their Sum(LeaveApplications.LeaveDaysTaken) AS LeaveDays column returns NULL. What i would like to do is place a value of 0 (Zero) instead of NULL. I want to do this because i have a calculated column in the same query whose formular depends on the LeaveDays returned and when LeaveDays is NULL, the formular some how fails. Is there away i can put 0 for NULL such that that i can get my desired result.
I was wondering if there's a drawback (other than bad practice) to using something like this
SELECT * FROM my_table WHERE id LIKE '1';
where id is an integer. I know you're supposed to use id=1 but I am writing a java program and if everything can use LIKE it'll be a lot easier for me. Also, so far, everything works fine; I get the correct query results, so if there is no drawback I will continue doing it like this.
edit: I am using MySQL.
var groups = from p in dc.Pool
join pm in dc.PoolMembers on p.ID equals pm.PoolID
group p by p.Group into grp
select new { grp.ID };
This isn't working. Basically I want to do the grouping, and then select certain columns, but when I do select new { grp. } I get no intellisense, so I'm obviously doing something wrong.
Any ideas?
how to avoid duplicate insert in a table? I use below query to insert in to table:
insert into RefundDetails(ID,StatusModified,RefundAmount,OrderNumber)
select O.id,O.StatusModified,OI.RefundAmount,O.OrderNumber
from Monsoon.dbo.[Order] as O
WITH (NOLOCK) JOIN Monsoon.dbo.OrderItem as OI
WITH (NOLOCK)on O.Id = OI.OrderId
WHERE o.ID in (SELECT OrderID
FROM Mon2QB.dbo.monQB_OrderActivityView
WHERE ACTIVITYTYPE = 4 AND at BETWEEN '10/30/2012' AND '11/3/2012') AND (O.StatusModified < '11/3/2012')
I have a table with 5 string columns, all can be NULLs. After I read the data from this table, I want to convert any null values into empty strings. The reason is that I need to compare these columns with columns in another table of the same schema (using conditional split), and null values would cause the comparison to evaluate to NULL.
Is there any functionality in SSIS that allows me to convert NULL's to empty strings, or just not having to deal with NULL's at all?
Hi al,
we have 5 tables over which we should query with user search input throughout a stored procedure. We do a union all of the similar data inside a view. Because of this the view can not be materialized. We are not able to change these 5 tables drastically (like creating a 6th table that contains the similar data of the 5 tables and reference that new one from the 5 tables).
The query is rather expensive / slow
what are our other options? It's allowed to think outside the box. Unfortunately I cannot give more information like the table/view/SP definition because of customer confidentiality...
greetings,
Tim
What is the most effective and flexible way to generate combinations in TSQL?
With 'Flexible', I mean you should be able to add easily combination rules. e.g.: to generate combinatories of 'n' elements, sorting, remove duplicates, get combinatories where each prize belongs to a different lottery, etc.
For example, Having a set of numbers representing lottery prizes.
Number | Position | Lottery
---------------------------
12 | 01 | 67
12 | 02 | 67
34 | 03 | 67
43 | 01 | 89
72 | 02 | 89
33 | 03 | 89
(I include the position column because, a number could be repeated among different lottery's prizes)
I would like to generate combinatories like:
Numbers | Lotteries
-------------------
12 12 | 67 67
12 34 | 67 67
12 34 | 67 67
12 43 | 67 89
12 72 | 67 89
12 33 | 67 89
.
.
.
If i have a table with two fields.customer id and order.
let's say i have in total order ID 1,2,3,4
all the customer can have all the four orders.like below
1234 1
1234 2
1234 3
1234 4
3245 3
3245 4
5436 2
5436 4
you can see above that 3245 customer doesnt have order id 1 and 2.
how could i print in the query output like
3245 1
3245 2
5436 1
5436 3
EDIT: i dont have order table but i have list of order's like we can hard code it in the query(1,2,3,4) i dont have an orders table.
I'm trying to modify a stored procedure hooked into an ORM tool. I want to add a few more rows based on a loop of some distinct values in a column. Here's the current SP:
SELECT
GRP = STAT_CD,
CODE = REASN_CD
FROM dbo.STATUS_TABLE WITH (NOLOCK)
Order by STAT_CD, SRT_ORDR
For each distinct STAT_CD, I'd also like to insert a REASN_CD of "--" here in the SP. However I'd like to do it before the order by so I can give them negative sort orders so they come in at the top of the list.
I'm getting tripped up on how to implement this. Does anyone know how to do this for each unique STAT_CD?