Showing posts with label mssql. Show all posts
Showing posts with label mssql. Show all posts

Monday, March 26, 2012

Getting string part based on some character in MSSQL

Hi,
I have one Req where I have to get the portion of the string ,like I have one e-Mail iD "shivendra.narayan@.rediffmail.com". I need only rediffmail.com now. Means to say get the string after the '@.'

PLZ help me

Thank You,
Shivendra

Quote:

Originally Posted by shivendra

Hi,
I have one Req where I have to get the portion of the string ,like I have one e-Mail iD "shivendra.narayan@.rediffmail.com". I need only rediffmail.com now. Means to say get the string after the '@.'

PLZ help me

Thank You,
Shivendra


-----------

Declare string_index int
Declare col_length int
select string_index = PATINDEX('%@.%', columnname),
col_length = length(columnname)
FROM tablename
WHERE 'Write your condition here'
Now, you can use the query below to return the
SELECT SUBSTRING(columnname, string_index, (col_length - string_index))
from tablename WHERE 'Write your condition here'

Hope this helps!!
Thanks!
Santhosh

Friday, February 24, 2012

Getting executed query details from MSSQL Log

Hi all,
plz consider this in urgent manner. Let me tell the situation. Someone
executed a query on a table around 5 hrs before. Is it possibel to get to
know that what query and from where and when it happened. Will the .ldf file
reader helps me in this ' ... plz iam waiting for the reply...
thanks in advance
--
Deepson ThomasGoogle for "dbcc log".
Understanding the SQL Server Transaction Log
http://www.windowsitlibrary.com/Content/77/21/1.html
AMB
"Deepson Thomas" wrote:
> Hi all,
> plz consider this in urgent manner. Let me tell the situation. Someone
> executed a query on a table around 5 hrs before. Is it possibel to get to
> know that what query and from where and when it happened. Will the .ldf file
> reader helps me in this ' ... plz iam waiting for the reply...
> thanks in advance
> --
> Deepson Thomas|||> plz consider this in urgent manner. Let me tell the situation. Someone
> executed a query on a table around 5 hrs before. Is it possibel to get to
> know that what query and from where and when it happened. Will the .ldf
> file
> reader helps me in this ' ... plz iam waiting for the reply...
If the log is not cleared, Lumigent Log Explorer or some other log reader
could help you (http://www.lumigent.com/products/le_sql.html).
--
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com

Getting executed query details from MSSQL Log

Hi all,
plz consider this in urgent manner. Let me tell the situation. Someone
executed a query on a table around 5 hrs before. Is it possibel to get to
know that what query and from where and when it happened. Will the .ldf file
reader helps me in this ? ... plz iam waiting for the reply...
thanks in advance
Deepson Thomas
Google for "dbcc log".
Understanding the SQL Server Transaction Log
http://www.windowsitlibrary.com/Content/77/21/1.html
AMB
"Deepson Thomas" wrote:

> Hi all,
> plz consider this in urgent manner. Let me tell the situation. Someone
> executed a query on a table around 5 hrs before. Is it possibel to get to
> know that what query and from where and when it happened. Will the .ldf file
> reader helps me in this ? ... plz iam waiting for the reply...
> thanks in advance
> --
> Deepson Thomas
|||> plz consider this in urgent manner. Let me tell the situation. Someone
> executed a query on a table around 5 hrs before. Is it possibel to get to
> know that what query and from where and when it happened. Will the .ldf
> file
> reader helps me in this ? ... plz iam waiting for the reply...
If the log is not cleared, Lumigent Log Explorer or some other log reader
could help you (http://www.lumigent.com/products/le_sql.html).
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com

Getting executed query details from MSSQL Log

Hi all,
plz consider this in urgent manner. Let me tell the situation. Someone
executed a query on a table around 5 hrs before. Is it possibel to get to
know that what query and from where and when it happened. Will the .ldf file
reader helps me in this ' ... plz iam waiting for the reply...
thanks in advance
Deepson ThomasGoogle for "dbcc log".
Understanding the SQL Server Transaction Log
http://www.windowsitlibrary.com/Content/77/21/1.html
AMB
"Deepson Thomas" wrote:

> Hi all,
> plz consider this in urgent manner. Let me tell the situation. Someone
> executed a query on a table around 5 hrs before. Is it possibel to get to
> know that what query and from where and when it happened. Will the .ldf fi
le
> reader helps me in this ' ... plz iam waiting for the reply...
> thanks in advance
> --
> Deepson Thomas|||> plz consider this in urgent manner. Let me tell the situation. Someone
> executed a query on a table around 5 hrs before. Is it possibel to get to
> know that what query and from where and when it happened. Will the .ldf
> file
> reader helps me in this ' ... plz iam waiting for the reply...
If the log is not cleared, Lumigent Log Explorer or some other log reader
could help you (http://www.lumigent.com/products/le_sql.html).
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com

Getting Exception , please help !

Hi all,

I am using MSSQL Server 8.0 , and the driver jtds.jar to connect the database for SQL operation .

I can do all the sql operation .
But after the creation of a trigger for a table , I used the same java program to insert rows into table .

---The java code I used -------
String connectionString = "jdbc:jtds:sqlserver://localhost:1433/master";
try {
Class.forName(jdbcDriverClass);
Connection con = DriverManager.getConnection(connectionString,userN ame,password);
Statement st = con.createStatement();
String query = "insert into tabname values('11','ROBERT')";
st.executeUpdate(query);
} catch (Exception e) { e.printStackTrace(); }
---------------

and got the exception

////////////////////////////////////////////////////////
java.sql.SQLException: executeUpdate can't return a result set
at net.sourceforge.jtds.jdbc.TdsStatement.executeUpda te(Unknown Source)
////////////////////////////////////////////////////////

What will be the problem here ?
Is it bcos of any time out ?
Please help !!!

ThanksPost the trigger.|||CREATE TRIGGER trigName ON tabname for
INSERT , UPDATE , DELETE
AS

DECLARE @.cont varchar(255)
DECLARE @.insRsltCount int
DECLARE @.delRsltCount int
DECLARE @.newVAL_0 char(10)
DECLARE @.newVAL_1 char(10)
SELECT @.insRsltCount = COUNT(*) FROM Inserted WHERE name IS NOT NULL OR num IS NOT NULL
SELECT @.delRsltCount = COUNT(*) FROM Deleted WHERE name IS NOT NULL OR num IS NOT NULL
IF(@.insRsltCount>0) AND (@.delRsltCount=0)
BEGIN
DECLARE INS_CURSOR CURSOR FOR SELECT name, num FROM Inserted
OPEN INS_CURSOR
FETCH NEXT FROM INS_CURSOR INTO @.newVAL_0,@.newVAL_1
WHILE @.@.FETCH_STATUS = 0 AND @.insRsltCount>0
BEGIN

SELECT @.cont = ' echo tabname.name="'+LTRIM(RTRIM(@.newVAL_0))+'" >>D://MyFolder//trigName.dat'
Exec master..xp_cmdshell @.cont
SELECT @.insRsltCount = @.insRsltCount-1
FETCH NEXT FROM INS_CURSOR INTO @.newVAL_0,@.newVAL_1


END
CLOSE INS_CURSOR
DEALLOCATE INS_CURSOR
END|||The usage of xp_cmdshell has been altered with the release of SP3 (SQL2K) and SP4 (7.0). From then on the security context is being verified within the procedure which is extended stored procedure, and if a user who caused (in your case) the trigger to fire does not belong to SYSADMIN server role, - the procedure will not execute.