views:

110

answers:

4

I'm having an issue I'm generating sudoku puzzles and the solution to the puzzle are being stored in this format: xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx

8 spaces between the 9 sets, I cannot seem to query the row, it returns a blank row..

Is this because there is spaces? If I do a select where solution like 'xxxxxxxxx%' then the row returns properly..

Did I just generate 50,000 rows for nothing :( If so how should I fix this spacing problem?

edit here is the query:

select * from sudoktion_puzzles 
where
p_solution='582917643 467283195 391546278 159362784 
674851329 823794561 216438957 938675412 745129836'
+4  A: 

In the query you quoted, you have two spaces before the second-to-last term (the one beginning with '9'). If that's your actual query code but not the actual value in the table, it would explain your problem.

Larry Lustig
Argh! I lost being first by 13 seconds!Yup, that's what I saw. Remove the second space and I'll bet the query will work.
Tenner
Sorry guys thats not the actual query SO code snipplet is being weird there's only one space infront of the second to last term!
Jreeter
+1  A: 

About the only thing peculiar about spaces you really need to remember about SQL Server (ANSI compliant) is that trailing spaces are not factored into LEN() or equality comparisons.

Is there anything peculiar about your data types?

Are they long enough to hold the entire string (at least 89 characters)?

If you want to get rid of the spaces, you can simply remove the spaces with:

UPDATE sudoktion_puzzles
SET p_solution = REPLACE(p_solution, ' ', '')
Cade Roux
fixed the query snipplet the query is actually one space before the last term, still returns blank results
Jreeter
I've gotten rid of all white space and it still returns blanks, my p_solution is a varchar(max)
Jreeter
Don't use varchar(max) for a column like this.
Cade Roux
would you suggestion varchar(89)?
Jreeter
I'd actually suggest char(89) since they will all be the same. There's no savings to be had choosing varchar(89). And they don't vary.
Cade Roux
That probably isn't your problem, though.
Cade Roux
+1  A: 

Double check that there isn't a second space anywhere, before or after.

Run

SELECT * FROM sudoktion_puzzles
 WHERE LEN(p_solution) <> 89

and see if you return the row you can't get otherwise. If so then you have extra spaces.

Tenner
that returned 0 rows!
Jreeter
Could it be some type of implicit type conversion? Perhaps your string of 81 digits are being interpreted as a number?(Just guessing at this point.)
Tenner
I'm almost about to blame godaddy's crappy sql server.. :/ The query Cade gave me doesn't seem to be replacing whitespace
Jreeter
+1  A: 

Hey guys those spaces were actually newline/enter characters this fixed it:

UPDATE sudoktion_puzzles
SET p_board = REPLACE(REPLACE(REPLACE(p_board, CHAR(10), ''), CHAR(13), ''), CHAR(9), '')
Jreeter