Help With TSQL To Combine Lastname And First Initial From Full Name
Aug 16, 2007
Hello fellows,
I am trying to write a query, here is the detail:
I have a table of users. Table schema:
FULL NAME, LOGIN
example data:
Anderman John, AndermaJ
Williams Robin, WilliamR
Foot Jay, FootJ
The LOGIN field will be my resulting field after I run my query.
It has a "FULL NAME" column, and a "LOGIN" column. I want to extract the first 7 characters of LAST Name from the FULL NAME field and extract the First Name Initial(just first letter of the first name) from the FULL NAME field and then set the LOGIN field with the resulting combination. The FULL NAME column is in the order of LastName FirstName.
Here is what I have been trying to write:
Declare @spacePos as int
Select @spacePos = charindex(' ', fullname) From TIUSER
Update TIUSER
SEt LOGIN = ltrim(Substring(fullname, 1, 7)) + Substring(fullname,@spacePos+1,1),
where @spacePos <> 0 and LOGIN = ' '
Currently we only have last and first names in our database and we will keep it that way since we don't store middle names and hopefully that will not be an issue.
But it seems that my solution was not working since if the last name is less than 7 characters then it should only grab upto the SPACE and not beyond that , but it was grabbing beyond the SPACE so how do you fix that?
That is I want atmost 7 characters from LAST NAME but incase of less than 7 then upto the space found.
My users wanted to view all the "FIRST and LAST" Lastname in each of the LastName initial in the database. I have been trying to join/connect/subquery/merge/etc the following two set of codes but without good results.
Fist, i get all the lastname initials: SELECT DISTINCT LEFT(LastName, 1) AS LastNameInitial FROM Persons.Persons ORDER BY LastNameInitial
Results to: -------------------------------------- A B C D ... Y Z
Then, i want to get all the FIRST and LAST LastName for each LastNameInitial I only have this partial idea (can't get the rest): -------------------------------------- SELECT MIN(LastName) + ' - ' + MAX(LastName) AS LastNameGroup FROM Persons.Persons WHERE (LastName LIKE 'A' + '%')
Only results to: -------------------------------------- Abad - Ayun
MY USERS WANTED TO HAVE THIS RESULT (In a single query): ------------------------------------------ Abad - Ayun Babaran - Buted Cabaccan - Curugan Dacquil - Durwin Eda - Evangelista ... Yadao - Yumul Zalun - Zunajo
Error log: full-text crawl logs for details. 2007-06-01 07:33:55.63 spid25s Error: 7683, Severity: 16, State: 1. 2007-06-01 07:33:55.63 spid25s Errors were encountered during full-text index population for table or indexed view '[XXXX].[dbo].[RECORDS]', database 'XXXX' (table or indexed view ID '738101670', database ID '17'). Please see full-text crawl logs for details. 2007-06-01 07:33:55.63 spid25s Changing the status to MERGE for full-text catalog "XXXX" (21) in database "XXX" (17). This is an informational message only. No user action is required.
This happens for every table that has membership in the full text storage, it is not specific to a database or column type
Scrawl Log: 2007-06-01 07:33:00.57 spid23s Informational: Full-text Full population initialized for table or indexed view '[XXXX].[dbo].[ATTACHMENTS]' (table or indexed view ID '517576882', database ID '17'). Population sub-tasks: 1. 2007-06-01 07:33:36.20 spid23s Error '0x80070003' occurred during full-text index population for table or indexed view '[XXXX].[dbo].[RECORDS]' (table or indexed view ID '738101670', database ID '17'), full-text key value 0x00002B59. Attempt will be made to reindex it. 2007-06-01 07:33:55.63 spid25s Informational: Full-text retry pass of Full population completed for table or indexed view '[XXXX].[dbo].[RECORDS]' (table or indexed view ID '738101670', database ID '17'). Number of retry documents processed: 31899. Number of documents failed: 31899. 2007-06-01 07:33:55.63 spid25s Changing the status to MERGE for full-text catalog "XXXX" (21) in database "XXXX" (17). This is an informational message only. No user action is required. 2007-06-01 07:33:56.59 spid23s Informational: Full-text Auto population initialized for table or indexed view '[XXX].[dbo].[RECORDS]' (table or indexed view ID '738101670', database ID '17'). Population sub-tasks: 1.
Hello, I need some help being pointed in the right direction. I have a field in my Customer table called Name that is "LastName,FirstName". I need to be able to return a result set with "FirstName,LastName". Any ideas?
I'm sure you all have seen situations where a field has a combined namein the format of "Lastname, Firstname Middlename" and I've seenexamples of parsing that type of field. But what happens when the datawithin this type of field is inconsistent? Here are some examplesApple, John A.Berry John B.CherryJohn CDonald John DHow does one parse the data when the data isn't consistent?
Can anyone please give me the equivalent tsql for sql server 2000 for the following two queries which works fine in sql server 2005
1 -- Full Table Structure
select t.object_id, t.name as 'tablename', c.name as 'columnname', y.name as 'typename', case y.namewhen 'varchar' then convert(varchar, c.max_length)when 'decimal' then convert(varchar, c.precision) + ', ' + convert(varchar, c.scale)else ''end attrib,y.*from sys.tables t, sys.columns c, sys.types ywhere t.object_id = c.object_idand t.name not in ('sysdiagrams')and c.system_type_id = y.system_type_idand c.system_type_id = y.user_type_idorder by t.name, c.column_id
2 -- PK and Index select t.name as 'tablename', i.name as 'indexname', c.name as 'columnname' , i.is_unique, i.is_primary_key, ic.is_descending_keyfrom sys.indexes i, sys.tables t, sys.index_columns ic, sys.columns cwhere t.object_id = i.object_idand t.object_id = ic.object_idand t.object_id = c.object_idand i.index_id = ic.index_idand c.column_id = ic.column_idand t.name not in ('sysdiagrams')order by t.name, i.index_id, ic.index_column_id
This sql is extracting some sort of the information about the structure of the sql server database[2005] I need a sql whihc will return the same result for sql server 2000
I have been using a licensed copy of Visual Studio 2005 and MS SQLServer 2005 for some time but am only now trying out the Reporting Services functionality.
I have attempted to follow the instructions from url:
However despite confirming that the report services are running and also checking the configuration by following the information in the above web page I still get the following problems.
1. When attempting to create a project via the wizard I get the following error: Exception has been thrown by the target of an invocation. If an attempt is made to add a new data source I am unable to choose the data source type (eg: Microsoft SQL Server). I am not given a choice for the type, in fact the relevant drop down is blank.
2. A project can be created without the wizard but if I right click the Shared Data Source folder I do not see the next Pop up to set the data source parameters.
I assume I am missing something quite fundamental - however so far I cannot see what.
Hi all. The company I work for is looking for a new SQL server. Where can I find information and or a tool for sizing information? By sizing information I mean how big a pile of hardware am I going to need to run MS SQL for x number of connected users with x size database, etc. I've been tooling around the internet and MS' site but can't find any info on this.
i have created a publication whereas i have provided a network path to its snapshop folder e.g ( \serverfolder ) at time of creating. When i try to make a Pull Subscription and follow all steps of wizards, it gives me following error "The initial snapshot for publication '---' is not yet available". can you guide me what are causes of this problem and how may i solve it?
I want get get results in sql that are all written in UPPERCASE but I want to receive them in Initial Case format I know UPPERCASE is UPPER lowercase is lower but what is Initial Case(first letter Capital in a word)
We had a runaway query which built the size of tempdb to 24000mb. Then someone changed the unrestricted file growth property to restricted growth while the size was 24000mb. Now I can not reduce the initial size. I have set the property back to unrestricted file growth. I have shrunk the tempdb and available space is almost 24000mb. I have stopped sqlserver. I even deleted the existing tempdb.mdf & tempdb.ldf files. But when SQL server is restarted, the initial size is set to 24000mb. It will not let me reduce the size. Is there anything short of manipulating the system tables to reduce the size back to 500mb?
I would like to increase the initial size of a SQL 2005 DB from 150 to 250 GB to prevent automatic autogrowth; would this have any impact in production if you do it on the fly?
I need to display the middle initial from a name field that contains the last name, comma, and the middle name or initial.
Example data:
Jane,Smith Ron John,Dow L Mary Jane,Dow Welsh
The result I am looking for is to capture only the first letter of the middle name. In this data example, I would need to display the following on a separate column:
-- I have a first name field that sometimes contains only the first name, -- sometimes contains the first name and the middle initial, and -- sometimes contains the first name, a space, followed by NMI (for no middle initial) -- how do I correctly grab the first letter of the middle initial in all cases? -- I have been playing with patindex but its harder than I thought. guess I need a case -- statement in addition to this. Any idea how I can do this? -- thanks!
I'm not a sql server savvy, so I need assistance on the following two scenarios:
A customer runs a script like this (slightly larger, but I ripped away the meat) --------------------------------------- create database test_database go
USE [test_database] exec sp_changedbowner 'sa'
use master; go sp_grantlogin 'server01CUSTOM_ADMIN'; go
use test_database; go
-- lots of table creations, where one of the tables are TEST_TABLE
sp_addrole 'ADMIN_ROLE'; Go sp_grantdbaccess @loginame = 'server01CUSTOM_ADMIN', @name_in_db = 'USER_ADMIN'; go sp_addrolemember @rolename ='ADMIN_ROLE' , @membername = 'USER_ADMIN'; Go
GRANT SELECT , UPDATE , INSERT , DELETE ON [dbo].[TEST_TABLE] TO [ADMIN_ROLE] GO ---------------------------
Now, if a person is added to the server01CUSTOM_ADMIN group, he/she should be able to do the following: (let's say it's a he)
- Create a test.udl-file (win xp). Set a provider to sql server. - On the connection-tab enter hostname of database server in the Data Source-field and use windows NT Integrated security. - When he now test the connection, it should work, since he has access to the database. - Also, using the dropdown "3. Enter the initial catalog to use:", he should see SOME datatables. Not ALL, not none. The ones that he has access to.
So, if TEST_DATABASE is the only access that server01CUSTOM_ADMIN has, that database and only that one should show, right?
In my customers scenario, some databases show (irrelevant ones), but not TEST_DATABASE. In my test, I still get ALL databases. Even after I rip the guy out of the Administrators-group and Users-group. He's only a member of the CUSTOM_ADMIN-group on server01. "Test connection" succeeds, and all the databases on the server shows.
What I hope for is following questions like "He's probably sysadmin, check it" etc, so that I can systematically (using your brains) filter out the reasons for these scenarios to happen.
Is there a way to decrease the initial size of a database/log file? I've noticed you can increase it, but if you decrease it, after you confirm the change and go checking again, you will see nothing happened.
Currently my db size is only 6 GB but the transaction log file initial size was set to 20 GB and has grown much way beyond the db size with the autogrowth feature turn on. The database was originally a test/development DB and was migrated to a production server including the log file. This probably caused the accumulation of transactions on the log.
We run backup everyday and tried to shrinkfile and file size did not change.
Can I change the "initial size" setting of the transaction log without causing any problems? Do I need to stop the service before I made the change assuming I made the change after the backup run? Or can I change it on the fly?
Via t-sql, how can I query for a file's initial size?
I want the same thing one finds by : Start SQL Server Management Studio, view, object explorer, right click [dbname], properties, files, Database files: Initial Size (MB).
Many thanks.
Anything will give up its secrets if you love it enough. -- George Washington Carver
Added four new equally sized .mdf files to a production tempdb last night and restarted the instance. I was hoping to remove the initial file as it's not required and does not match the size+growth of the others. The option to 'remove' it is greyed out in the files tab of the GUI so I'm assuming that ALTER DATABASE [tempdb] REMOVE FILE [tempdev] will also fail.
Do I need to migrate any data in this particular .mdf before it can be dropped? Or would the simplest approach be to change the size of this file to match the others and drop tempdev3?
I have a SQL Server 2005 Std. Ed. 64-bit installation. There is one instance supporting a single production database. I have a CLR udf. This udf uses the XMLDocument object to retrieve XML from a URL. When the CLR udf is executed, there seems to be an initial slow response time. Subsequent response times are very fast. If the CLR udf is not called for a few minutes and then called, the slowdown appears again.
Is there something happening behind the scenes with compilation or something like that which could cause this slowdown?
I am setting up 2005 Transacational Replication on a database that was created on SQL 2000. There are 1400 articles (tables, views, sp and functions). It takes 2.5 hours to create the snapshot. Then, once the distribution errors gets its first error, it keeps retrying and getting the same error. Q1: Can I tell it to record the error but keep going? Q2: How do I stop the distribution agent once it gets in the this state? I have been deleting the publication but that seems like overkill.
I am trying to figure out a more efficient way to identify all the articles that are going to get errors. Is there any way to test the articles to see which ones will get an error? My current process takes a long time just to identify one error (since I have to create the snapshot each time).
I connect, but when I try to access any table from this database I get an error indicating that the object doesn't exist and if I use the fullname xx.table I get no errors. What may be happening?
I would like to increase the initial size of a SQL 2005 DB from 150 to 250 GB to prevent automatic autogrowth; would this have any impact in production if you do it on the fly?
HI all... I am using MS SQL 2000 DB...from last 4 months....I want to take backup of the data from 1st january to 29th Feb 2004 and then trim this data to freeup some space in my dtabase. Is it possible?if yes hOW? Thanks in advance, Chandresh here
Hi, In a .net application there is a link that brings up a SSRS report. I have noticed that if it is the first time this report is requested i.e. Application has just been opened and the report button is clicked, then it takes a while to get this report to appear on the screen. But if this report is requested again (i.e. for the second time or more) then it only takes a few moments for the report to appear on the screen. So it seems that only the first time the report is requested it takes a longer time to get this report. Is there a way to reduce this initial load of the report? Thanks
A failure occurred when accessing 'MSmerge_contents_table290_forall.bcp' due to an operating system error [3='The system cannot find the path specified.'] during Web synchronization. Ensure that the -InternetLogin user when using basic authentication and the user running the merge when using Windows integrated authentication has been granted access to the snapshot share.
A failure occurred when accessing 'MSmerge_contents_table290_forall.bcp' due to an operating system error [3='The system cannot find the path specified.'] during Web synchronization. Ensure that the -InternetLogin user when using basic authentication and the user running the merge when using Windows integrated authentication has been granted access to the snapshot share.
The processing of the response message failed.
I've tried compressing the snapshot, and can see the bcp file in the snapshot.