|
Hi,
Have the following case statement:
select
case
when upper(code) = 'TWASH' then (@t_wash = count(ISNULL(code,0)))
when upper(s5.code) = 'TT-WASH' then (@tt_wash = count(ISNULL(s5.code,0)))
end
from table
for some reason it keep coming back with "Incorrect syntax near '='." that would be the first "when" statement. Can we assign variables in case-statement?
Thanks.
|
|
|
|
|
Hi - solved this using another way. Looks like you cannot assign values in then part of statement.
select @t_wash = case when upper(code) = 'TWASH' then count(ISNULL(code,0))
same for other - you get the basic idea.
Thanks.
|
|
|
|
|
hi,
try the following links, hope you will get some idea to solve the problem.
1 [^]
2 [^]
best regards.
_____________________________
Success is not something to wait for, its something to work for.
|
|
|
|
|
I believe you're missing a select or set before the variable:
VK-Cadec wrote: when upper(code) = 'TWASH' then (set @t_wash = count(ISNULL(code,0)))
|
|
|
|
|
I did try that - it did not help.
|
|
|
|
|
Hello,
I'm trying to use NHibernate, but I have several problems.
First of all, I am not sure that my App.config file works. Here it is:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</configSections>
<nhibernate>
<add
key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider"
/>
<add
key="hibernate.dialect"
value="NHibernate.Dialect.MsSql2005Dialect"
/>
<add
key="hibernate.connection.driver_class"
value="NHibernate.Driver.SqlClientDriver"
/>
<add
key="hibernate.connection.connection_string"
value="Server=localhost;initial catalog=pruebaNHibernate;Integrated Security=SSPI"
/>
</nhibernate>
</configuration>
I'm trying to connect to a SQL Server 2005 database, but when I run my application, I get this error message:
Unhandled Exception: NHibernate.MappingException: Could not instantiate dialect
class NHibernate.Dialect.MsSql2005Dialect ---> NHibernate.HibernateException: Co
uld not instantiate dialect class NHibernate.Dialect.MsSql2005Dialect ---> Syste
m.TypeLoadException: Could not load type 'NHibernate.Dialect.MsSql2005Dialect, N
Hibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc', c
heck that type and assembly names are correct
I think that it is cause the value of the key hibernate.dialect isn´t correct. Does anyone know what I have to put there? I found the dialect for almost any type of db except SQL Server 2005.
Thank you for your help!
|
|
|
|
|
Hi
I am running my database on a shared 3rd party server.
Recently, when I try to connect to the DB from my website, Asp.net gives me the following error:
"SQL Server does not exist or access denied."
[SqlException: SQL Server does not exist or access denied.]
System.Data.SqlClient.ConnectionPool.GetConnection(Boolean& isInTransaction) +474
System.Data.SqlClient.SqlConnectionPoolManager.GetPooledConnection(SqlConnectionString options, Boolean& isInTransaction) +372
System.Data.SqlClient.SqlConnection.Open() +384
MyCompany.WebModules.Data.DbObject.RunProcedure(String storedProcName, IDataParameter[] parameters, String tableName)
.....
....
For instance, this morning the website was working fine, but now suddenly, I am getting the above error. The same problem happened on other days, as well.
Do you think, there is a problem with my code, or is this SQL Server problem?
|
|
|
|
|
Hi hasanali00
Did you try pinging the server when you got the error message in order to confirm that there were no connectivity issues?
Also place code so that yuo can catch the exception where it is being thrown and output the error message. That way you will be more clear on the part of code is throwing the exception and what the error message is saying.
Thanks and Regards,
Aby
|
|
|
|
|
the problem was that the log file was full:
run this command to delete the log:
dump transaction DATABASE_NAME with no_log
|
|
|
|
|
Hello friends,
I'm developing a .NET application using VS2005 and I want to use NHibernate to implement the persistence.
By the moment, in the hibernate web page, there are only two versions, the 1.0.2 version and the 1.2.0 version, which at this moment is only a beta version.
My question is: Are both versions compatible with .NET 2.0 and VS2005? Wich one should I use?
|
|
|
|
|
How can I back up data from 19 division servers to one main sql server once a day which are connected by VPN?
I read some articles about Replication/Publication function. But I never being use that function and not sure does it work in the way that I want????
Any one can help????
|
|
|
|
|
Hi,
I have a stored proc(below) which assigns tasks to an employee depending on which division they are in.
This is working fine, but is only selecting the first name in the database it comes to.
In order for the workload of task assigning to be spread evenly I need to come up with some way as to "sequentially" select and employee??
ie. each time a do a select I want to pick a different employee from the database until I get to the last employee in which I repeat the process.
I thought of doing a random generator function first but this would probably be unfair as some employees MAY get assigned more tasks than others.
Any ideas??
CREATE PROCEDURE sp_GetAssignedDetails<br />
@roleName nVarChar(50), <br />
@division nVarChar(50),<br />
@actorName nVarChar(50) OUTPUT,<br />
@actorLogon nVarChar(5) OUTPUT<br />
AS<br />
<br />
IF @division = 'North'<br />
BEGIN<br />
--Get ActorName and ActorLogon if division is North<br />
SELECT @ActorName = dbo.Actor.ActorName<br />
FROM dbo.Actor INNER JOIN<br />
dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
WHERE dbo.ActorRole.RoleName = @roleName<br />
and dbo.ActorRole.North = '1'<br />
<br />
SELECT @actorLogon = dbo.Actor.ActorLogon<br />
FROM dbo.Actor INNER JOIN<br />
dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
WHERE dbo.ActorRole.RoleName = @roleName<br />
and dbo.ActorRole.North = '1'<br />
END<br />
--Get ActorName and ActorLogon if division is South<br />
ELSE IF @division = 'South' <br />
BEGIN<br />
SELECT @actorName = dbo.Actor.ActorName<br />
FROM dbo.Actor INNER JOIN<br />
dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
WHERE dbo.ActorRole.RoleName = @roleName<br />
and dbo.ActorRole.South = '1'<br />
<br />
SELECT @actorLogon = dbo.Actor.ActorLogon<br />
FROM dbo.Actor INNER JOIN<br />
dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
WHERE dbo.ActorRole.RoleName = @roleName<br />
and dbo.ActorRole.South = '1'<br />
END<br />
--Get ActorName and ActorLogon if division is West<br />
ELSE IF @division = 'West' <br />
BEGIN<br />
SELECT @actorName = dbo.Actor.ActorName<br />
FROM dbo.Actor INNER JOIN<br />
dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
WHERE dbo.ActorRole.RoleName = @roleName <br />
and dbo.ActorRole.West = '1'<br />
<br />
SELECT @actorLogon = dbo.Actor.ActorLogon<br />
FROM dbo.Actor INNER JOIN<br />
dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id<br />
WHERE dbo.ActorRole.RoleName = @roleName <br />
and dbo.ActorRole.West = '1'<br />
END
-- modified at 16:05 Tuesday 31st October, 2006
|
|
|
|
|
I've had an idea (off the top of my head so bear with me ).
What if I create a temp table.
Then everytime I do a select on the main table I insert the actor to the temp table then everytime I go to assign details I do a check
if actor exists in temp table
get next person from main table
repeat this until we get to the end of the table and do somekind of compare count on both tables to establish we have gone through everyone. Then drop the temp table, re-create it and start it all again?? Clear as mud!!
Anyone know best way to compare the count on the two tables so I can then clear the temp table and start over again.
Or if anyone has a better idea please let me know
|
|
|
|
|
I'm not sure I understand what you are trying to do regarding 'assigning tasks to an employee depending on which division they are in', but this code does the same thing as that which you provided...only it is a bit shorter.
CREATE PROCEDURE sp_GetAssignedDetails
@roleName nVarChar(50),
@division nVarChar(50),
@actorName nVarChar(50) OUTPUT,
@actorLogon nVarChar(5) OUTPUT
AS
SELECT @ActorName = dbo.Actor.ActorName,
@actorLogon = dbo.Actor.ActorLogon
FROM dbo.Actor INNER JOIN
dbo.ActorRole ON dbo.Actor.Id = dbo.ActorRole.Id
WHERE dbo.ActorRole.RoleName = @roleName
and '1' = case when @division = 'North' then dbo.ActorRole.North
when @division = 'South' then dbo.ActorRole.South
when @division = 'West' then dbo.ActorRole.West end
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Thanks for that EricDV.
Basically what I'm trying to do is......
If I have 20 employees in my Actor Table I need to select one that hasn't been selected before each time I go to the Actor Table.
This is required so that a different employee is assigned a task every time I call the sp_GetAssignedDetails from my application.
Once I get to the last employee and assign him/her a task, all employees have now had a task assigned so I then want to go back to employee No.1 and start all over again.
Any ideas?
|
|
|
|
|
You could have a datetime field (LastAssignment) in the Actor table. Then, assign the next task to the oldest LastAssignment Actor, and update their LastAssignment.
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
Here is an idea:
- Create a new table PickOrder with 2 columns - division and chosenName.
- Iniitialize PickOrder with 4 records -
('North', 'a1')
('South', 'a1')
('East', 'a1')
('West, 'a1')
Now, in sp_GetAssignedDetails,
1- Get the chosenName value (cn) from the PickOrder table for the requested division.
2- Using your query, select the top 1 record WHERE actorName > cn ... ORDER BY actorName
3- if no record is found in step 2 and there are existing records for that division (i.e., we have exhuasted the list), set the chosenName to 'a1' and repeat step 2 to start with the first name.
4- Update the chosenName column value in PickOrder table with the actorName found in step 2, so that next time we can pick the next name.
-- modified (added ORDER BY clause) at 22:08 Thursday 2nd November, 2006
|
|
|
|
|
Hi
I have to insert new rows from a dataset wich has many tables (8), with the same schema, to an Sql server database. The dataset is filled from an xml file that is quite a bit large.
My question is which is the best solution to insert these new rows from the dataset with a transaction (to be updated all the tables or in case of fail rollback), to the Sql database?
Any ideea are welcome.
biglewy
|
|
|
|
|
hello everyone. I was wondering if someone could help me.
As a debugging aid i want to see how many times my stored-proc is called and i also want to record certain variables. I would like to write this information to a text file on c:\ of the SQL Server. I am using MS Sql Server 2000..
Can anyone point me in the right direction please.
Thanks
|
|
|
|
|
after some googling i have sorted my problem..
thanks
|
|
|
|
|
here is a stored-proc which writes to a file
<br />
IF OBJECT_ID('dbo.sp_TestWriteToFile') IS NOT NULL<br />
DROP PROC dbo.sp_TestWriteToFile<br />
GO<br />
CREATE PROCEDURE [dbo].[sp_TestWriteToFile]<br />
AS<br />
exec master..xp_cmdshell 'echo hello > c:\file.txt'<br />
exec master..xp_cmdshell 'echo blah de blah > c:\file.txt', no_output<br />
<br />
GO<br />
SET QUOTED_IDENTIFIER OFF <br />
GO<br />
SET ANSI_NULLS ON <br />
GO<br />
<br />
exec sp_TestWriteToFile
and here is one which appends data to a file:
<br />
IF OBJECT_ID('dbo.sp_TestWriteToFile') IS NOT NULL<br />
DROP PROC dbo.sp_TestWriteToFile<br />
GO<br />
CREATE PROCEDURE [dbo].[sp_TestWriteToFile]<br />
AS<br />
exec master..xp_cmdshell 'echo appended data >> c:\file.txt'<br />
GO<br />
SET QUOTED_IDENTIFIER OFF <br />
GO<br />
SET ANSI_NULLS ON <br />
GO<br />
<br />
exec sp_TestWriteToFile
-- modified at 11:40 Tuesday 31st October, 2006
|
|
|
|
|
hi guys
i have one insert query in which i am selecting values from another table and then insert it in first table
Query is like this.
table1 table2
userid group id
groupid group name
i have values of userid and groupname
insert into table1 (userid,groupid) values
(userid,select groupid from table2 where groupname="temp"))
it is not working so if anyone knows how to do it please help me out
DJ
|
|
|
|
|
insert into table1(userid,groupid)
select userid, groupid from table2 where groupname="temp"
cheers,
Neil
|
|
|
|
|
What would be the best way to store a strict hierarchy (like a "Help Contents" tree) in a database?
Is there a "standard solution"?
I'm more looking for alternatives, but here's what seems most natural to me: Storing just the parent in the same table as the items
id PKey, nchar name, id PKeyOfParent
e.g.
0, "Root", 0 (predefined ID)
1, "Child1", 0
2, "Child2", 0
3, "A GrandChild", 1
4, "Another GrandChild", 2
to get all immediate childs of MyID is simply WHERE PKeyOfParent=MyID
Advantage: No redundant data, orphaned items (parent does not exist are easily found.
Disadvantages: orphaned "cycles" are possible. can SQL Server can be forced to keep integrity itself (e.g. recursively deleting all descendants?). "IsDescendant" probably cannot be written as a single select (stored procedure maybe?)
The application I'm thinking of introduces a "secondary" M:N mapping anyway, but from my judgement, a more restrictive hierarchy would help the user a lot.
Also, for the amount of data I imagine it would be no problem to read the entire index, then build the tree in the client, but that sounds just wrong.
We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
Linkify! || Fold With Us! || sighist
|
|
|
|
|
I'm currently writing an application that has heirarchical data. We have a similar solution, the table contains an Id to its parent (null at the top of the heirarchy). The IsDecendant problem is one we also have, however we store a second, denormalised, table for that. The denormalised table has just two columns ID and decendantID.
Using your example data the denormalised table will look like this:
ID decendentID Comments
---------------------------------------------
0 0 -- [Root + Decendents]
0 1
0 2
0 3
0 4
1 1 -- [Child1 + Decendents]
1 3
2 2 -- [Child2 + Decendents]
2 4
3 3 -- [A GrandChild + Decedents]
4 4 -- [Another GrandChild + Decendents]
Then it is easy to query to see if something is a decendent of another thing:
SELECT *
FROM DenormalisedHeirarchy
WHERE decendentID = @decendentID
AND ID = @somethingID
The trick is keeping the denormalised set up to date. In our case we don't have too many inserts/updates so we can afford to have a trigger regenerate part of the denormalised table when changes occur.
Does this help?
|
|
|
|