Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   [SHARE][MSSQL QUERY] Find non existing accounts with existing chars (https://postpacific.loc-online.com/showthread.php?t=7322)

m4rk 09.04.2007 15:10

[SHARE][MSSQL QUERY] Find non existing accounts with existing chars
 
Abstract: I found this problem while deleting unused and banned accounts. I realized there were some (few but some after all) accounts that were deleted even if they had characters on them. So I built this query to get the ID of those accounts. Hope this saves you some time if you need this.

Check the second post by Sauron

This one will just print the account_id
Code:

--declare variables
declare @max int
declare @current int
declare @exist int

--set variables
USE LIN2WORLD
SET @max = (SELECT TOP 1 account_id from user_Data        ORDER BY account_id DESC)
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id!= -1 ORDER BY account_id ASC)

--loop condition
WHILE @current<@max

BEGIN

USE LIN2DB
SET @exist = (SELECT COUNT(*) FROM user_account WHERE uid=@current)
IF @exist = 0
PRINT @current

USE LIN2WORLD       
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id>@current ORDER BY account_id ASC)

END


This one will return the SELECT * FROM user_data WHERE account_id= the non existing account in LIN2DB
Code:

--declare variables
declare @max int
declare @current int
declare @exist int

--set variables
USE LIN2WORLD
SET @max = (SELECT TOP 1 account_id from user_Data        ORDER BY account_id DESC)
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id!= -1 ORDER BY account_id ASC)

--loop condition
WHILE @current<@max

BEGIN

USE LIN2DB
SET @exist = (SELECT COUNT(*) FROM user_account WHERE uid=@current)
IF @exist = 0
BEGIN
USE LIN2WORLD
SELECT * FROM lin2world.dbo.user_data WHERE account_id=@current
END

USE LIN2WORLD       
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id>@current ORDER BY account_id ASC)

END


Sauron 09.04.2007 16:03

Code:

SELECT DISTINCT(account_id)
FROM lin2world.dbo.user_data
WHERE account_id > 0 and account_id not in (SELECT uid FROM lin2db.dbo.user_account)


m4rk 09.04.2007 17:39

Thanks Sauron, i knew there had to be an easiest way.

seraphii 09.04.2007 17:45

M4rk when you delete one char from your db ,you delete only from user_data??

m4rk 09.04.2007 18:05

Mmh no I delete from many other tables (i modyfied a query share by Kin).

seraphii 09.04.2007 19:41

can you share... i do something like that....


All times are GMT. The time now is 15:25.