Saturday, February 7, 2015

Write T-SQL code to take m valid values from User and provide all valid Sudoku possibilities for nXn matrix

Continue to my last post “Write T-SQL code to provide all valid Sudoku possibilities for nXn matrix.

I modified the procedure sc.cp_Create_MetrixPosibilities_nXn which also take m valid values from User for matrix and create table dbo.MetrixPosibilities_nXn with all valid Sudoku possibilities.

Below are parameters for the procedure sc.cp_Create_MetrixPosibilities_nXn.

  1. @p_MatrixSize
    1. Size of matrix for which we want to create all the possibilities.
  2. @v_PositionMatrixValue
    1. Table Value Parameter which is used to pass valid user entries. Below is structure of TVP.
      1. PositionX
      2. PositionY
      3. Value

Suppose, we have 4X4 matrix with below values for which I want to create all valid possibilities

4X4 - Copy

We can execute procedure as below.

Declare @v_PositionMatrixValue as PositionMatrixValue

Insert into @v_PositionMatrixValue values(1,1,1)
Insert into @v_PositionMatrixValue values(2,2,2)
Insert into @v_PositionMatrixValue values(3,3,3)
Insert into @v_PositionMatrixValue values(4,4,4)

EXEC sc.cp_Create_MetrixPosibilities_nXn 4, @v_PositionMatrixValue, 0
Go

Select * From MetrixPosibilities_4X4

Here, we have 2 valid possibilities created as below in table dbo.MetrixPosibilities_4X4.

image

Below are the scripts to download.

1. sc.cp_Create_MetrixPosibilities_nXn_V2.sql

No comments:

Post a Comment