I want to create a stored procedure which will extract the "GroupName"
from the record returned by "sp_helpuser". In order to do this I need
to execute "sp_helpuser" which returns the entire record. I want to
just extract the "GroupName" from the record and return it to my
application. How do I go about this?
I am trying to add data to 2 columns CaseResolvDatetime and CaseResolvGroupName based on the criteria: 1. for a CallID, the last datetime where Resolution='Resolved' 2. where there is no 'Resolved', the 2nd last datetime & groupname for a particular CallID
INSERT @table(CallID, ResolvDatetime, GroupName, Resolution, CaseResolvDatetime, CaseResolvGroupName) SELECT '00458176','08/1/2005 1:41:54 PM','Field Sup CoOrd','Resolved',Null,Null UNION ALL SELECT '00458176','08/9/2005 3:35:24 PM','Service Desk','Reassigned',Null,Null UNION ALL SELECT '00458176','08/12/2005 9:54:37 AM','BSSAppSvcs-Club','Reassigned',Null,Null UNION ALL SELECT '00458176','08/16/2005 10:32:40 AM','CDR SysOps','Reassigned',Null,Null UNION ALL SELECT '00458176','08/24/2005 11:18:30 AM','CDR Server','Reassigned',Null,Null UNION ALL SELECT '00458176','08/24/2005 2:13:15 PM','Field Sup CoOrd','Reassigned',Null,Null UNION ALL SELECT '00458176','08/24/2005 4:01:24 PM','CDR Server','Resolved',Null,Null UNION ALL SELECT '00458176','08/25/2005 4:29:44 PM','Field Sup CoOrd','Reassigned',Null,Null UNION ALL SELECT '00458176','08/26/2005 2:59:19 PM','Service Desk','Reassigned',Null,Null UNION ALL SELECT '00458176','09/9/2005 10:42:44 AM','Field Sup - Vic','Completed',Null,Null UNION ALL SELECT '00461166','09/7/2005 9:49:02 AM','BSSAppSvcs-Apps','Resolved',Null,Null UNION ALL SELECT '00461166','09/7/2005 10:26:42 AM','Service Desk','Completed',Null,Null UNION ALL SELECT '00461166','09/9/2005 10:19:13 AM','BSSAppSvcs-Apps','Reassigned',Null,Null UNION ALL SELECT '00461166','09/15/2005 1:15:00 PM','Service Desk','Reassigned',Null,Null UNION ALL SELECT '00461166','09/15/2005 1:15:11 PM','Service Desk','Resolved',Null,Null UNION ALL SELECT '00456633','08/08/2005 1:18:32 PM','BSSAppSvcs-Club','Completed',Null,Null UNION ALL SELECT '00456633','08/26/2005 2:02:07 PM','Service Desk','Completed',Null,Null UNION ALL SELECT '00456633','08/26/2005 3:31:36 PM','Service Desk','Completed',Null,Null
SELECT CallID, ResolvDatetime, GroupName, Resolution, CaseResolvDatetime, CaseResolvGroupName FROM @table
UPDATE @table
SET CaseResolvDatetime = CASE WHEN Resolution = 'Completed' AND CallId = (select CallId from @table where GroupName like 'Ser%' AND Resolution = 'Completed') then ResolvDatetime ELSE NULL END
SELECT CallID, ResolvDatetime, GroupName, Resolution, CaseResolvDatetime, CaseResolvGroupName FROM @table -------------------------------------------------
At the moment I get the error:
Server: Msg 512, Level 16, State 1, Line 25 Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. The statement has been terminated.
Yet when I change the line:
"where GroupName like 'Ser%'" to "where GroupName like 'CDR%'" ... I get no error.
I set up a group within an SQL Server database, of which I am a member. In some visual basic code, I do a dislay of user names.
My question: why does the code show my individual name (Servermyname) as opposed to showing the group name I want to see? I have confirmed that the only user of the database is the group, and not an individual user name.
Any ideas? Thanks!
********************************************************************* This forum is best viewed with a computer. Questions asked freely. Confusion happily shared.
I am working on creating a configuration database. This will connect to many databases on many different servers. What I would like to do is run sp_MSForEachDB then store the name of the current server and database the package is connected to. Then add both of these into a column before running sp_helpuser. I don't know how confusing this is, but I think I may have the code worked out pretty well. If you have any questions, please post them and I will try to answer as best as I can. What I would like the ending result to look like is...
If sp_helpuser showed some Username with (null) LoginName, I believe these must be some obsolete username defined in the database before ,can I have them cleaned up , anyone has this experience ?
Also, I was able to find out from sp_who, or select * from sysprocesses the active login id to the system, is there quick way ,stored procedure etc to find out the usernames for the current active session for a particular database ?? I don't think these usernames are shown up in the current activity under EM..
I have a table that has the first name and last name together in one field (stupid I know). I want to extract the first name from the field and copy it into another field names, well, firstname. I figure it might be possible since there is a comma after the last name. But how can I do this?
So for:
STRNAME ------------- adams, john ------------- washington, michael -------------
I want it to be like this
STRNAME | STRFIRSTNAME --------------------------- adams | john --------------------------- washington | michael
So I guess there would be two parts to the statement:
1. First I need to select or trim the strname field to the comma. BUT I don't want to just trim it- I want to copy it.
2. The next thing I need to do is to copy the lastname (the part that I trimmed) into a new field which I created called lastname.
I posted this a while ago with no luck and I'm going to try it again:
I have a column called strlastname with contains the firstname and last name of a client. I want to separate out the first name and last name into into two separate fields. I figured maybe I can do it easier if I copied the column into the table. So now I have a column called strfirstname that contains the first name and the last name and a colmn called strlastname that contains the first name and last name. The lastname is seperated from the first name with a comma like this:
I need to find rows from the above table which has the first occurence of the corresponding ID. This the output will contain the rows that will have first occurence of the following ids.
1067381, 1087668, 109754, 1103377.
How does one handle this. I have not been able to come up with the sql yet.
I have a package which establishes connection with DB2 server.I dont have any db2 application where i can format query for db2.This is my query in access/sql. can someone help me converting it into a db2 query.i tryed to google and use the functions but i failed and even the error that ssis gives don't help asthey are same for any type of error. Thanks in ADV
SELECT table1.YYYY & table1.MM as MO_YR, table2.CNTRYCD AS CNTRY_CD, Sum(table1.AMT) AS [VALUE] FROM table1 INNER JOIN table2 ON (table1.MM = table2.MM) AND (table1.YYYY = table2.YYYY) WHERE (table1.YYYY BETWEEN YEAR(DATE()) AND YEAR(DATEADD("m",-3,DATE()))) AND (table1.MM BETWEEN MONTH(DATE()) AND MONTH(DATEADD("m",-3,DATE()))) GROUP BY table2.CNTRYCD, table1.YYYY, table1.MM
I need to get some data from an enormous, creaky old SQL 6.5 database.I know nothing about either the data schema (though I believe some sortof documentation exists), nor 6.5 for that matter, having come to SQLServer at 7.0.My clients need the data in comma delimited format.Please, can anyone suggest any possibilities? One thing that occurredto me might be to create an Access application, use an ODBC link to theSQL DB, and then leverage Access' not inconsiderable functionality toget the data out.Does anyone foresee any problems with this, or any better ways?Forever in your debt.Edward--The reading group's reading group:http://www.bookgroup.org.uk
'm trying to get the value from a column in a SQL Server table that contains XML but the type of the column is not XML it is TEXT.
I tried this:
SELECT [Id], [Request] FROM [Tracker] WHERE [Request].value('/Credit[1]/Loan[1]/LoanApp[1]/Applicant[1]/Personal[1]/Individals[1]/Individual[1]/GivenName[1]/FirstName[1]', 'nvarchar(50)') = 'Tom'
but I get this error :
Cannot find either column "Request" or the user-defined function or aggregate "Request.value", or the name is ambiguous.
I tried to cast the column like this:
select CAST(CAST(Request AS NTEXT) AS XML).value('(/Credit[1]/Loan[1]/LoanApp[1]/Applicant[1]/Personal[1]/Individuals[1]/Individual[1]/GivenName[1]/FirstName[1]', 'nvarchar(50)')
from Tracker but with this I get this error:
XML parsing: line 1, character 15, A string literal was expected
hii all i am havie a database with given fileds like projectid,projectcode,projectname,startdat,enddate,etc.... my problem is to show all months and year between each projects startdate and enddate in a datagrd..and the table dont have month, year field.. i need to use sql quiery.. if anybody can help me in this matter.. it will be greatful.. thanks in advance..binoy
Hi, I'm hoping someone has an idea or two on this topic. Basically I have three tables of data say tContact, tQuestion, tAnswer
tContact ----------- ContactID Email Name
tQuestion ------------ QuestionID Question
tAnswer ------------ QuestionID ContactID Answer
I need to extract the data for the client and they would like to see the data with one line per contact, but showing every answer to every question... they would like the data formatted like this:
Obviously to get the data I cansimply do an outerjoin to get all contact data then all questions, and answers that exist... but that will obviously return tabular data with one row per each answer... Does anyone have any ideas on how to do this using just SQL? I can pull the data and write a function that spits it out to text using the Stringbuilder class and some logic, but I'm thinking this must be possible in SQL natively... any help would be more than appreciated. Thanks in advance.
Lets say I have a column of type varchar and need to extract an integer value from the middle of it. The string looks like this:'this part is always the same' + integer of varying length + 'this part is different but always the same length'Is there a way to trim the constant string lengths from the beginning and end?
Hi,I'm using MSSQL2k and I have some customers in a customer table. I want to write a webapp and offer them the possibility to teach them using the app while having telephone contact with them. They can use the app on my server for some time and add data to it.After a while when someone wants to buy the app I would like to distribute the app as an Intranet app to their own server and let them have the data they already have wrote into the db on my server.Because there will be some customers with much data I'd like some guidance in how to plan the database to easily extract their own data and create a new db polutated with their data.Kenneth
Hi, I'm inserting records into a Table1 with the following fields : tabID int 4ClientID int 4..etc etc. In the insertitem template, I want the user to enter a Clientcode into textbox1. Then I want that client code validated against a lookup table, ClientTable and if valid, get the ClientId value from that ClientTable, so that I can populate the ClientID field in Table1. I've got a mental block and I cannot see how I can do that ! Any ideas most gratefully appreciated. Thanks Sunil
As I can extract the hour values and minute of a field of type datetime to compare it with the values of a field of type smalldatetime of another table
Hi i have a query select 12 * int( "SQLUSER"."BTT120".yyyy) + int("SQLUSER"."BTT120".mm) as actual, 12*year(CURRENT DATE) + month(CURRENT DATE) as ending, 12*year(CURRENT DATE) + month(CURRENT DATE)-3 as starting from "SQLUSER"."BTT120" where "SQLUSER"."BTT120".yyyy ='2007' and "SQLUSER"."BTT120".mm in ('10','11','12')
which gives me ourput
Actual ending Starting 24094 24097 24094
My actual requirment is to get the data for the rolling 3 months for which i used the same logic as above in the WHERE clause.
SELECT "SQLUSER"."BTT120".YYYY CONCAT "SQLUSER"."BTT120".MM AS MO_YR FROM "SQLUSER"."BTT120" where (12 * int( "SQLUSER"."BTT120".yyyy)) + int("SQLUSER"."BTT120".mm) between (12*year(CURRENT DATE)) + month(CURRENT DATE)-3 and (12*year(CURRENT DATE)) + month(CURRENT DATE)
everything looks good but iam not getting output, there is data for the date range
"Current Date updated ( 12/31/2015 -> 12/31/2016 )" "Status updated ( Open -> Should be Closed )" From example 1 ==> need outputs of " 12/13/2015" and "12/31/2016"; example 2 --> need outputs of "Open" and "Should be Closed"
These are what all records look like:
1. It contains the word, "updated". 2. There is a space after the last character of updated. Then, there is a space before open parenthesis. Then, there is a space before getting the required word. Example: "updated ( xxxxx" (xxxxx is a required extract word.) 3. The entire word(s) should be captured before the "->" sign (after the open parenthesis) 4. The last part is to captured everything after the "->" but before the close parenthesis ")"
What would the syntax be to insert a column to the right of this one, and extract the first 8 digits from the data in the DATEID column and insert that into the new column DATE, therefore making it easier for me to query against an actual date?