|
Good Day All
I have the Following SP
ALTER PROC GET_BASED_PATTERN
(
@SUBJECT VARCHAR(30),
@Pattern nvarchar(128) output
)
AS
SET @Pattern = (SELECT TOP 1 TERM.[CYCLETEMPLATES]FROM tbl_term TERM
INNER JOIN dbo.TBL_ACTV v
on TERM.ID = V.TERM
INNER JOIN DBO._Subjects S
ON V.TERM = S.[LEVEL]
WHERE CODE = @SUBJECT)
SELECT
CASE
WHEN LEN(@Pattern) > 1 THEN @Pattern
ELSE '00000000'
END
It returns
00000000
and NUll at the Bottom if the len is not greater than 1. i want it to return 00000000 if its like that.
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Not sure what you need but if you want to get the same value in both the places, here's a way:
SET @Pattern = (SELECT TOP 1 TERM.[CYCLETEMPLATES]FROM tbl_term TERM
INNER JOIN dbo.TBL_ACTV v
on TERM.ID = V.TERM
INNER JOIN DBO._Subjects S
ON V.TERM = S.[LEVEL]
WHERE CODE = @SUBJECT)
IF @Pattern is null Set @Pattern = '00000000'
Select @Pattern
Hope that helps.
Regards,
Syed Mehroz Alam
My Blog
My Articles
Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
|
|
|
|
|
Hi,
Is it possible to append more conditions to a WHERE clause dependant on a condition? This is what i'm trying to do at the moment with no joy.
E.G.
...
WHERE
(@extOrderID IS NULL OR Orders.ExtOrderID = @extOrderID) AND
(@orderDateAfter IS NULL AND @orderDateBefore IS NULL OR Orders.TimeOrdered >= @orderDateAfter AND Orders.TimeOrdered <= @orderDateBefore) AND
(@requiredDispatchDateAfter IS NULL AND @requiredDispatchDateBefore IS NULL OR (DATEADD(day, (SELECT SLA FROM Product WHERE Product.ID = OrderItem.ProductID), Orders.TimeOrdered)) >= @requiredDispatchDateAfter AND (DATEADD(day, (SELECT SLA FROM Product WHERE Product.ID = OrderItem.ProductID), Orders.TimeOrdered)) <= @requiredDispatchDateBefore) AND
(@customerForename IS NULL OR Customer.Forename LIKE @customerForename) AND
(@customerSurname IS NULL OR Customer.Surname LIKE @customerSurname) AND
(@customerPostCode IS NULL OR Address.PostCode LIKE @customerPostCode) AND
CASE WHEN @orderStatus IS NOT NULL THEN
CASE WHEN @statusChecked = 'False' AND Status.StatusName != @orderStatus THEN 1
WHEN @statusChecked = 'True' AND Status.StatusName = @orderStatus THEN 1
ELSE 0
END
END <> 0
AND
CASE WHEN @isSearch = 1 THEN
Orders.IsActive = 1
END
It is the last CASE which is not working, any suggestions would be appreciated!
Phil
|
|
|
|
|
Are you meaning that when @isSearch = 1 then Order.IsActive must equal 1 to return the row?
If so, no you can't do that, but you could do this
AND (@isSearch = 0 or Orders.IsActive = 1)
Regards,
Rob Philpott.
|
|
|
|
|
Rob Philpott wrote: Are you meaning that when @isSearch = 1 then Order.IsActive must equal 1 to return the row?
Yes that is what I meant, can you think of possibly another way then of how I could dynamically create my where clause based on the parameters passed. I have found away to do this but it involves using an IF to see if @isSearch = 0 and then having the same query but with Order.IsActive = 1 on the end of one of them. Obviously I'd prefer to not do this as I'm just repeating code.
|
|
|
|
|
The clause in my previous post will do it.
Regards,
Rob Philpott.
|
|
|
|
|
The only reaslistic alternative is to use dynamic SQL (sql strings) but that is plain ugly.
Also chaining multiple conditionals can nail a query to the wall. What I often do is use the "required" conditions to get a subset into a temp table and then start deleting records from the temp table or use the conditional filtering on the temp table
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
in oracle we can call a function like this in stored procedure
create or replace procdeure getitems
(
item in varchar2
)
begin
item :=getitems(sysdate);
end;
but how the function is called in sql server 2005 in an sp
|
|
|
|
|
lakshmichawala wrote:
but how the function is called in sql server 2005 in an sp
It all depends what your function returns.
If your function returns a scalar value then you can use the function as
select dbo.getitem(itemid) from Items
or if your function returns a table then you can do some thing like this,
select item_code,item_desc from dbo.getitems(getdate())
hope that helps....
When you fail to plan, you are planning to fail.
|
|
|
|
|
hi
we can also assing like this na
set @item =dbo.getitems(getdate())
|
|
|
|
|
Hi evryone
Is it posible to install Oracle 10G on Windows XP ?
I try to install and the installation stuck in "Ocacle Database Configuration Assistant"
|
|
|
|
|
E_Gold wrote: Is it posible to install Oracle 10G on Windows XP ?
Runs fine on my XP system.
E_Gold wrote: I try to install and the installation stuck in "Ocacle Database Configuration Assistant"
No error message?
I are troll
|
|
|
|
|
I have also installed without any problem
i think you need to re-install windows xp.
|
|
|
|
|
Hi all,
I have implemented a functionality shown here[^] on codeproject.
This method generates xml from ntext and inserts it into table.
Now i want a trigger on this table which inserts in other table when each row is inserted.But the problem is that when the trigger fires, the inserted table contains all the rows that are inserted in the table (i guess since it was inserted all at once) and hence i m not able to insert it in other table bcas i have to perform some operation on the data also.
Is there a method so that the trigger fires for each row and not all at once????
When you fail to plan, you are planning to fail.
|
|
|
|
|
I have not used openxml so I am assuming a bulk insert is used and the trigger is by passed (I also never, ever use triggers). So why not grab the Details ID, insert the records, get the last ID inserted, call a proc for the detail between. Ugly and subject to other user interference.
OR
Don't use openxml - I am surprised the insert does not fire the insert trigger
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello Friends,
I've to store more than 10000 characters in Sql. But when i store more than 8000 it throws an error........ How can i do it
|
|
|
|
|
What Datatype are you using to Store those Characters ?
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
|
I've done it by using the following command
Create Table Rough2(Name varchar(Max))
|
|
|
|
|
Try this
NVARCHAR(MAX)
or
NTEXTMAX)
Hope it Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Use the text or ntext datatype to store large texts if you don't plan to use them in queries (e.g. where PlaceName = "Amsterdam" is a varchar , but the wikipedia-text on Amsterdam is a text -field)
I are troll
|
|
|
|
|
Good Morning Friends,
I have a SP that is Supposed to Restore a Database from a Backup. In some Clients this works well but in those particular client its a Problem. The version is SQL 2005.
Here is the Code that fails
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- Restore a backed up database
-- Given: the filename and path where the backedup database file is located and the name of the database to restore it as
-- The entry will be restored and a row placed into oDirect.dbo.tbl_dbref - which keeps track of the databases
-- The users for the database must also be restored!
ALTER PROCEDURE [dbo].[sp_RestoreDatabase]
@dbname char(32), -- the database name to restore as
@filename char(64), @path char(256) -- the location of the backuped up database file (on the SQL Server)
AS
set nocount on
declare @sql nvarchar(3000)
execute('sp_ClearDatabaseConnections ' + @dbname)
-- Restore the database
select @sql = ' RESTORE DATABASE ' + ltrim(rtrim( @dbname )) + ' FROM DISK = ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @filename )) + ''' '
select @sql = ltrim(rtrim(@sql)) + ' WITH RECOVERY, '
select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name
select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + 'TNGoedit_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name
--select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Data' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '.mdf' + ''' , ' -- logical file name to physical name
--select @sql = ltrim(rtrim(@sql)) + ' MOVE ''' + ltrim(rtrim(@dbname)) + '_Log' + ''' TO ''' + ltrim(rtrim(@path)) + ltrim(rtrim( @dbname )) + '_log.ldf' + ''' ' -- logical file name to physical name
print @sql
execute ( @sql )
-- Was the command successful or was there a problem
if ( (select @@Error) = 0 ) begin
-- Put an entry into oDirect.dbo.tbl_dbRef
-- execute ( 'sp_DataSet_Save ''' + @xml + ''' ' )
-- TODO: restore the users
select 'Restore Successful' [Result]
end
else begin
select 'Restore Unsuccessful' [Result]
end
And i get the Error
Exception caught in: ExecuteStoredProc: Could not continue scan with NOLOCK due to data movement. RESTORE could not start database 'Testv3'. RESTORE DATABASE is terminating abnormally. Database 'Testv3' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.
Thank you.
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Hi all,
How can we access a table located in different database server under different database.(In a stored procedure)
I mean can we do some thing like the following in a stored procedure to get the data from the remote table...
{
CONNECT TO THE REMOTE SERVER
SELECT THE TABLE DATA
}
Please let me know how to do this...
"Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)
|
|
|
|
|
NO NO NO
Lets say i have Table 1 in Server1 and Table2 In Server 2 and want to run a Query based on it. Well you must use a link Server and Call it with the instance of the Link Server like this
SELECT NAME.TABLE1,LASTNAME.TABLE
FROM TABLE 1 --IN THE CURRENT WORKING SERVER
INNER JOIN SERVER2.DATABASE.USER.TABLE2
ON USER_ID.TABLE1 = USER_ID.TABLE2
Hope this Helps
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
www.ITS.co.za
|
|
|
|
|
Hi, im having a little rpblem with sql's performance
The database engine installed fine and had been working fine
Then i installed the client tools and after installing that and restarting pc, the procesor suddenly goes to a 100% for a little while, when i open the task manager, the System process is the one that takes the 100% of the procesor capacity
This had happened before, and i had just unistalled the SSMS and the problem would disappear, but this is weird, i have installed sql server (complete installation) and it works fine (on windows xp)
This is a clean windows installation of windows xp also
Does anyone have had this problem??
Any suggestions
Thanks in advance
Alexei Rodriguez
|
|
|
|